SAN FRANCISCO — The California Supreme Court handed a victory Monday to organized farm labor in the state in a lawsuit that pitted the union launched by iconic labor leader Cesar Chavez against one of the largest U.S. fruit farms.

In a unanimous ruling, the highest court in the nation’s leading agricultural state upheld a law that allows California to impose labor contracts for farmworkers whose unions and employers do not agree on wages or other working conditions.

The decision maintains the power of farmworker unions by ensuring contracts that guarantee pay, hours and other terms that could otherwise be decided by employers.

Labor activists say the 2002 law is key to helping farmworkers improve working conditions by preventing employers from stalling contract talks to avoid a deal.

Opponents called the law government overreach that deprived agricultural employers and workers of any say over the terms of employment.

Gerawan Farming, which hires thousands of workers for its nectarine, peach and plum farms in California’s Central Valley, challenged the law in a fight with the United Farm Workers of America, co-founded by Chavez.

“We believe that coerced contracts are constitutionally at odds with free choice,” Dan Gerawan, who runs the company, said in an email after the ruling.

Gerawan Farming plans to appeal the ruling to the U.S. Supreme Court.

The United Farm Workers said in a statement that the court had rejected Gerawan’s arguments, and it accused the company of violating its workers’ right to a union contract.

The law in question allows the California Agricultural Labor Relations Board to order mediation to achieve a contract and gives mediators the authority to set the terms of the agreement if there is an impasse. The board can then force those conditions on companies and unions.

The California justices said the law did not violate the state Constitution because it provided enough guidance to mediators on how to decide contract disputes and furthered lawmakers’ goal of “ensuring that collective bargaining agreements are tailored to the unique circumstances of each employer.”

Unions can seek mediation 90 days after demanding to bargain on behalf of workers — even if the vote to unionize occurred decades earlier in some cases.

“The argument when it was enacted was that workers would get all fired up about having a union to represent them, and they would vote for the union, but then the employer would delay, and the workers would lose their enthusiasm,” said Philip Martin, a farm labor expert at the University of California, Davis.

He said 50 to 100 other farms throughout California may find themselves in the same position as Gerawan.

In court documents, the UFW said a previous law had failed to achieve California’s goal of providing millions of farmworkers the right to collective bargaining.

At the time the law was enacted in 2002, fewer than half of farm employers whose workers voted to join a union since 1975 had agreed to a labor contract, according to the UFW.

The union won the right to represent Gerawan Farming workers in 1990, but the sides did not agree to a contract. At UFW’s request, the California Agricultural Labor Relations Board in 2013 ordered Gerawan and the union into mediation, and the mediator eventually crafted a contract approved by the board.

An appeals court ruled two years ago that the law was unconstitutional because it failed to provide mediators with policy goals or standards and would result in a different set of rules for different employers.

The state Supreme Court said the possibility that mediators could treat farmers arbitrarily was not enough to make the law unconstitutional.

Complicating the fight is a vote Gerawan workers took in 2013 to decide whether to keep UFW as its union. The state labor relations board impounded the ballots over allegations of election misconduct, and they have not been counted. A separate legal challenge over the ballots is pending.