Europe Editor James Mates rounds up what happened at top-level discussions between 30 world leaders on Tuesday, with defence and support for Ukraine high on the agenda
Moscow’s invasion of Ukraine prompted the two nations to abandon their long-held non-aligned status and apply to join Nato, as protection against an increasingly aggressive and unpredictable Russia - which shares a long border with Finland.
But Turkish President Recep Tayyip Erdogan had blocked the move, insisting the Nordic pair must change their stance on Kurdish rebel groups that Turkey considers terrorists before it would back them joining.
Countries can only join Nato if all current members agree.
After urgent talks in Madrid on Tuesday, the alliance's Secretary General Jens Stoltenberg, said: “We now have an agreement that paves the way for Finland and Sweden to join Nato.”
Europe Editor James Mates explains what Sweden and Finland's new Nato memberships will mean
Finnish President Sauli Niinistö said the three countries’ leaders signed a joint agreement after talks on Tuesday.
Turkey said it had “got what it wanted” including “full cooperation" in "the fight against” the rebel groups.
Mr Stoltenberg said leaders of the 30-nation alliance will issue a formal invitation to the two countries to join on Wednesday.
The decision has to be ratified by all individual nations, but he said he was “absolutely confident” Finland and Sweden would become members, something that could happen within months.
The move is not without risk for Finland and Sweden. Russia previously warned that if the two Nordic nations join Nato, they would instantly transform from neutral into hostile countries and "potential targets" for Russia.
Want a quick and expert briefing on the biggest news stories? Listen to our latest podcasts to find out What You Need To Know
Why has Turkey reversed its opposition?
Turkey hailed Tuesday’s agreement as a triumph, saying the Nordic nations had agreed to crack down on groups that Ankara deems national security threats, including the Kurdistan Workers’ Party, or PKK, and its Syrian extension.
It said they also agreed “not to impose embargo restrictions in the field of defence industry” on Turkey and to take “concrete steps on the extradition of terrorist criminals".
Turkey has demanded that Finland and Sweden extradite wanted individuals and lift arms restrictions imposed after Turkey’s 2019 military incursion into northeast Syria.
Swedish Foreign Minister Ann Linde told reporters that “all the parties showed an incredible willingness to get there and were constructive and we made it clear that we take these concerns about terrorist attacks... seriously.”
Turkey, in turn, agreed “to support at the 2022 Madrid Summit the invitation of Finland and Sweden to become members of Nato”.
A senior administration official said Washington played a crucial role in helping bring the two parties closer together, with President Joe Biden speaking with Erdogan on Tuesday morning at the behest of Sweden and Finland to help encourage the talks.
Mr Biden said Nato was “as united and galvanised as I think we have ever been.”
Why have Sweden and Finland decided to join Nato now?
Sweden, once a regional military power, has avoided military alliances since the end of the Napoleonic Wars.
Like Finland, it remained neutral throughout the Cold War, but formed closer relations with Nato after the 1991 Soviet collapse.
They no longer see themselves as neutral after joining the European Union in 1995, but have remained non-aligned militarily until now.
After being firmly against Nato membership for decades, public opinion in both countries shifted following Russia's February 24 invasion of Ukraine, with record levels of support for joining the alliance.
Under Nato treaties, an attack on any single member would be considered an attack against all and trigger a military response by the entire alliance.