Chilean President Sebastián Piñera had announced Wednesday that he was cancelling plans to host the meeting, as well as a summit of Asia-Pacific leaders, to focus on restoring security in his country following weeks of protests in which at least a dozen people have died.
Spanish Prime Minister Pedro Sánchez's office offered to step in at short notice Thursday, sending delegates from around the world scrambling to change their travel plans. Sánchez, who is facing a national election on Nov. 10, celebrated Friday's decision.
"Excellent news: Madrid will host the global climate meeting from Dec. 2-13. Spain is already at work to guarantee its staging of COP25. Our government firmly keeps its commitment to lasting progress and a just ecological transition," Sánchez wrote on Twitter.
Among those who were planning to attend the conference in Chile was Swedish activist Greta Thunberg, whose climate protests have helped inspire tens of thousands of mostly young people to take to the streets demanding greater efforts from world leaders.
The teenager made a high-profile crossing from England to New York by sailboat earlier this year and planned to travel overland to Santiago to speak at the meeting. Thunberg refuses to fly because of aviation's big carbon footprint.
After the move to Madrid was confirmed Friday, Thunberg appealed for help. "It turns out I've traveled half around the world, the wrong way," she tweeted. "Now I need to find a way to cross the Atlantic in November...," she added. "If anyone could help me find transport I would be so grateful."
Thunberg voiced regret about not being able to visit Central and South America as planned, saying she had been looking forward to doing so. "But this is of course not about me, my experiences or where I wish to travel. We're in a climate and ecological emergency," she said.
It wasn't immediately clear on what scale the conference will be held in Madrid. Last year's climate conference in Katowice, Poland, was attended by more than 20,000 people. The 25th Conference of the Parties, or COP25, is meant to work out some of the remaining unresolved issue on the rules that countries have to follow in their efforts to reduce greenhouse gas emissions.
The meetings have also become a venue for countries to announce new initiatives to respond to global warming.
Follow AP's full coverage of climate change issues at https://www.apnews.com/Climate