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.” Justices said the possibility that mediators could treat farmers arbitrarily was not enough to make the law unconstitutional.

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.