France becomes the first country in the world to pass such a law as President Emmanuel Macron says he wants France to become the global leader in the fight against global warming.
Only the right-of-centre Republicans opposed the legislation and some Socialists abstained.
No new permits will be granted to extract fossil fuels from this week and no existing licences will be renewed beyond 2040, when all production in France and its territories must cease, according to the new law.
Socialist parliamentarian Delphine Batho said she wanted the law to become “contagious”, inspiring larger extractors to set similar targets.
Macron has promised to replace any funding withdrawn from the UN climate change programme by Donald Trump.
France extracts an estimated 815,000 tonnes of oil or other fuels per year, which is an amount produced every few hours by Saudi Arabia.
France produced around 16,000 barrels of petrol per day last year, compared to Saudi Arabia, which extracted an estimated 10.4 million barrels per day that year.
But French environment minister Nicholas Hulot said the new law showed “current generations can take care of future generations”.
Macron has said he wanted France to take the lead as a major industrialised power by leaving fossil fuels and nuclear power and heading towards renewable sources.
He said he also hoped to stop the sale of diesel- and petrol-fuelled cars by 2040.
Macron tweeted: “Very proud that France has become the first country in the world today to ban any new oil exploration licences with immediate effect and all oil extraction by 2040.”
Macron has tried to claim the mantle of global climate leadership that Donald Trump abandoned after the US pulled out of the Paris climate accord in June.
Mocking Trump’s “Make America great again” catchphrase, Macron added the hashtag “Make our planet great again”.
The ban will affect companies looking for oil in the French Latin American territory of Guyana and the extraction of shale gas by any means.
Fracking was banned in France in 2011.
French Guyana might be affected by the ban. Picture credit: Wikimedia