A measure to tax Uber and Lyft rides to help pay for transportation improvements as the city continues to struggle with rising congestion was trailing by the slimmest of margins Wednesday morning.

The measure would raise up to $35 million a year to pay for changes such as adding more bike lanes and hiring more Muni drivers, a tiny amount compared to Muni’s $1.2 billion two-year budget.

Proposition D, the Traffic Congestion Mitigation Tax, had received just under two-thirds of votes with all precincts reporting, but some mail-in ballots left to be counted. It required a two-thirds margin to pass because the money was to be set aside for specific uses.

Uber and Lyft supported the measure, which would be in effect from 2020 to 2045, after negotiating with Supervisor Aaron Peskin because it was less onerous than his previous proposal, which would have taxed gross receipts. The companies were expected to pass the tax along to riders.

The tax would be 3.25% on most rides and 1.5% on shared rides. The lower rate would also apply to electric cars until the end of 2024. A $10 Uber or Lyft ride would be taxed 32.5 cents, while a $10 shared or electric ride shared would be taxed 15 cents.

Prop. D’s backers, which included Mayor London Breed and the entire Board of Supervisors, pointed to a city study concluding that a deluge of Uber and Lyft cars was responsible for two-thirds of San Francisco’s increased congestion over six years.

The new tax would apply to self-driving cars if Uber and Lyft start to offer paid rides in them. It would not apply to taxicabs or private cars.

Critics pointed out that the measure was unlikely to decrease the number of Uber and Lyft cars on the streets, and would allow the companies pass the costs on to their riders.

The money collected would be split between the San Francisco County Transportation Authority and the San Francisco Municipal Transportation Agency.

Carolyn Said is a San Francisco Chronicle staff writer. Email: csaid@sfchronicle.com Twitter: @csaid