It will become illegal to produce or look for oil and gas in the country and its overseas territories. Existing drilling permits will expire in 2040 and, from today, no new ones will be granted.
France is the first country in the world to pass such a law.
The change is unlikely to have a significant impact, given 99 per cent of France’s oil and gas is imported from other countries.
However, the French Government hopes the symbolic gesture will put pressure on other countries to adopt similar laws.
Mr Macron has said he wants France to become the global leader in the fight against global warming. He has promised to replace any funding withdrawn from the UN climate change programme by Donald Trump, and has announced plans to ban the sale of diesel and petrol cars in France by 2040.
World news in pictures
After the law banning oil and gas exploration was passed, Mr Macron wrote on Twitter: “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.”
Mocking Mr Trump’s “Make America Great Again” slogan, the French President added the hashtag “Make Our Planet Great Again”.
France produces 815,000 tonnes of oil per year – most of it from its South American territory of French Guiana.
The amount is equivalent to what a major oil producer such as Saudi Arabia would produce in just a few hours.
Despite this, Nicholas Hulot, the French Environment Minister, said the new law showed “current generations can take care of future generations”.