Firefighters in Spain and France were scrambling on Tuesday to keep ferocious wildfires near Madrid and Bordeaux in check before a scorching heat wave hits the area, which could worsen the largest blazes the countries have faced in their modern history.

Lt. Col. Éric Brocardi, a spokesman for France’s National Federation of Firefighters, told French radio on Monday that recent rainfall had given those battling the flames a short window of opportunity “to race against the clock” before the heat wave arrives.

Temperatures in parts of both countries are expected to climb to 104 degrees Fahrenheit, or 40 degrees Celsius, this week — the latest in a succession of extreme heat events that have dried out vegetation, combining with strong winds to increase the risk of fires spreading.

The fires in France and Spain have consumed scores of houses and burned hundreds of thousands of acres of land so far, highlighting the challenge faced by Europe as summers grow increasingly hot and wildfires become more widespread. Flames have come unsettlingly close to the Spanish capital and to Bordeaux, which is France’s sixth largest city and a famed center of its wine industry.

On Tuesday morning, officials in Spain said that the wildfires had been mostly contained overnight, thanks to milder temperatures.

“It has been a positive night,” Fernando Grande-Marlaska, Spain’s interior minister, told the Spanish public broadcaster. “Today we can rest a bit easier, given the weather conditions we will be facing in the coming hours,” he said.