The proposal came in response to a High Court deadline over how ministers would meet European Union limits on nitrogen dioxide pollution.
It is part of a package of measures to improve air quality in England, but the vehicle ban is also expected to cover Scotland, where air quality is devolved.
Motoring groups pointed to the potentially huge loss of tax revenue from engine bans, while environmental campaigners urged more action now.
There were also questions over whether electric and other zero-emission vehicles would be as affordable as petrol and electric cars in two decades’ time. Hybrid vehicles would also be covered by the ban.
The cost of providing enough re-charging points, and the ability of the national grid to cope with the extra demand for electricity are other concerns.
The UK Government proposal is similar to one announced by France. However, the Scottish Government claimed it was already ahead of the game.
In 2013, it announced “a key ambition is that by 2040 almost all new car sales will be near zero emission at the tailpipe and that by 2030 half of all fossil-fuelled vehicles will be phased-out of urban environments across Scotland.”
However, so far ministers have only announced a pilot low-emission zone, where the most polluting vehicles could be banned, in one city from next year. Both Glasgow and Edinburgh want to be chosen.
Environment secretary Roseanna Cunningham said: “No-one should be in any doubt about the Scottish Government’s determination to improve air quality and fight climate change.
“We want to achieve a dramatic increase in the percentage of ultra-low emission cars and vans on Scotland’s roads and it is encouraging to see the UK Government follow our lead. Our Cleaner Air for Scotland strategy sets out how we plan to ensure Scotland’s air quality is the best in Europe and work is already well underway to deliver Scotland’s first low emissions zone.
“Officials are studying the detail of the UK Government’s plans to phase out petrol and diesel cars and, crucially, what they mean for Scotland.”
WWF Scotland acting head of policy Gina Hanrahan called on Scottish ministers to commit to phase out such vehicles by 2030 in their forthcoming Climate Change bill.
She said: “Ending the dominance of fossil-fuel vehicles will reduce emissions, clean up our polluted air and tackle a public health crisis.”
Friends of the Earth Scotland also urged faster action.
Air pollution campaigner Emilia Hanna said: “Air pollution is a public health crisis which is killing thousands of people early every year, so a ban on sales of fossil-fuelled vehicles in 23 years time is simply not good enough.”
Environmental law firm ClientEarth, which took the UK Government to court to force action on air quality, said: “The 2040 diesel and petrol ban, while important, is a diversionary tactic and doesn’t deal with the public health emergency caused by illegally polluted air, now.”
Jim Holder, editorial director of What Car? magazine, said it would be “a tall order” to increase the market share of electrified vehicles from 4 per cent of new car sales today to 100 per cent in 2040.
A survey by insurer Aviva showed yesterday only 2 per cent of drivers planned to buy an electric car as their next vehicle.
Mr Holder said concerns over the charging infrastructure, the response of drivers to electric cars and the loss of billions of pounds of fuel duty meant “the risk is that this announcement creates more problems than it solves”.
AA spokesman Jack Cousens predicted the national grid would be under pressure to “cope with a mass switch-on after the evening rush hour”.
RAC spokesman Nick Lyes said: “The [UK] Government signalling the end of the sale of conventional petrol and diesel vehicles by 2040 is a bold move, but the UK is nowhere near ready for such a sweeping shift to electric vehicles and a huge amount of work will need to be done.”