Legislation passed Monday in Olympia will require automakers to make more  electric or other zero-emission vehicles available for sale in Washington.

State advocates of electric cars have been trying for years to get the measure approved, but in the past were unable to overcome opposition that included a trade association representing major automakers. This year, the measure passed the House, and on Monday it narrowly passed the state Senate on a 25-23 vote, pushed by a coalition of more than 40 groups that included environmentalists, the International Brotherhood of Electrical Workers, electric-car advocates and Tesla, the electric-car manufacturer.

“We had a lot of juice behind it,” said Matthew Metz, of Coltura, a Seattle-based organization that advocates for a transition away from fossil-fuel-powered vehicles as part of the effort to combat climate change.

The bill, which Gov. Jay Inslee supports, authorizes Washington to become one of 12 states to adopt California standards for zero-emission vehicles.

The bill requires automakers in 2022 to make about 5% of the vehicles sold in Washington state to be electric or other types of zero-emission vehicles such as those fueled by hydrogen, according to Metz. That will increase to around 8% by 2025. Companies that fail to meet the targets could purchase credits from other companies such as Tesla.

Under the California law, BMW, Fiat, Honda, Hyundai, Kia, Mercedez, Nissan, Toyota and Volkswagen are required to comply with the vehicle requirements, and five smaller manufacturers can meet their obligations with plug-in hybrids, according to the California Air Resources Board.

Metz said that some electric-car models that are now difficult to find in Washington should become more available once the bill becomes law.

In Olympia, Rep. Joe Fitzgibbon, D-West Seattle, and state Sen. Joe Nyugen, D-White Center, played important roles in getting the bill through the Legislature, according to Metz.