The law passed the Strasbourg assembly by 340 votes to 279, with 21 abstentions.
EU member states have already approved the legislation and will now formally nod it into law, despite opposition from conservative MEPs, the parliament's biggest group.
Supporters of the bill had argued to that it would give European carmakers a clear timeframe in which switch production to zero-emission electric vehicles.
This in turn will support the European Union's ambitious plan to become a "climate neutral" economy by 2050, with net-zero greenhouse gas emissions.
"Let me remind you that between last year and the end of this year China will bring 80 models of electric cars to the international market," EU vice president Frans Timmermans warned MEPs.
"These are good cars. These are cars that will be more and more affordable, and we need to compete with that. We don't want to give up this essential industry to outsiders."
But opponents argued that industry is not ready for such a dramatic cut off in production of internal combustion engine vehicles -- and that hundreds of thousands of jobs are at risk.
"Our proposal is ... to let the market decide what technology is our best to reach our goals," said MEP Jens Gieseke, a member of the centre-right European People's Party.
Gieseke declared that arguments from Green and socialist MEPs that electric cars are cheaper to run had been rendered "null and void" by the crisis of soaring energy costs.
"In Germany 600,000 people work on ICE production, those jobs are at risk," he declared, urging the European Commission to rethink plans to also extend the ban to trucks and buses.
Opponents also argue car batteries are produced abroad by Europe's competitors like the United States, but Timmermans argued that thanks to EU-backed investment European production would increase.