France is joining a growing movement to force the extinction of vehicles that run on fossil fuels, saying on Thursday that it would aim to end the sale of gasoline and diesel cars by 2040.

The target is less ambitious than ones set by countries like Norway and India. Still, coming from a major car-producing country, France’s declaration gave additional momentum to efforts to fight climate change and urban smog by promoting the use of electric cars.

The timing of the announcement was also significant, a day after the automaker Volvo said it would phase out the internal combustion engine, and during a visit to Europe by President Trump. The announcement by Nicolas Hulot, the French environment minister, was an expression of European leaders’ determination to pursue an environmental agenda despite Mr. Trump’s repudiation of the Paris agreement on climate change.

“It’s a very difficult objective,” Mr. Hulot said Thursday. “But the solutions are there.”

The plan to phase out gasoline and diesel cars is part of a broader effort by France to limit global warming, which Mr. Hulot outlined Thursday. The country will also stop issuing new oil and gas exploration permits this year, and stop using coal to produce electricity by 2022, he said.