Nato member Turkey has agreed to support Sweden and Finland's membership of the alliance.
It had initially opposed the Nordic countries' bids to join.
Turkey was angered by what it saw as their willingness to host Kurdish militants. Sweden and Finland could not join Nato without Turkey's support.
Russia strongly opposes the two states joining and has used the expansion of the West's defensive military alliance as a pretext for its war in Ukraine.
But Moscow's invasion has had the opposite effect, with the path now clear for the two countries to join Nato.
Foreign ministers from the three countries signed a joint security pact that addressed Turkey's concerns.
Nato chief Jens Stoltenberg said Sweden agreed to step up its work on Turkish extradition requests of suspected militants.
The two Nordic nations will also lift their restrictions on selling weapons to Turkey, he said.
Finland's President Niinisto said the three countries signed the joint memorandum "to extend their full support against threats to each other's security".
Sweden's Prime Minister Magdalena Andersson said it was "a very important step for Nato".
Turkey President Recep Tayyip Erdogan's office said it "got what it wanted" from Sweden and Finland.
The two Nordic nations announced their intentions to join Nato in May, in response to Russia's invasion of Ukraine.
Mr Stoltenberg had suggested the process could move "very quickly" as they already shared a close relationship with the alliance.
But that was not the case as Nato member Turkey accused the two countries of protecting Kurdish militants and said they would not back their membership. Any Nato enlargement must be approved by all 30 members.
Turkey has long accused Sweden of harbouring what it calls militants from the banned Kurdistan Workers Party (PKK), but Stockholm denies it.
Now the two countries have agreed to some of Turkey's demands, and militants will face a crackdown under amendments to Swedish and Finnish law.
If Sweden and Finland do become members, it will end over 200 years of Swedish non-alignment. Finland adopted neutrality following a bitter defeat by the Soviet Union during World War Two.
Finnish public support for joining Nato was for years at around 20-25%. But since Russia's invasion of Ukraine, it has shot up to a record high of 79%, according to the latest opinion poll. In Sweden, 60% of the population say it was right to apply, again far higher than before the war.
Baltic Sea to become a 'Nato lake'
The metaphoric champagne corks will be popping in Nato's senior ranks tonight as the biggest stumbling block is removed to admit two major new members.
Finland and Sweden are already modern, Western-leaning democracies with well-trained and well-equipped militaries used to operating in the often challenging conditions of Europe's far North.
Their accession, once it is complete, will bring the number of Nato countries bordering the Baltic Sea to eight, effectively turning it into a Nato lake.
Russia's two outlets, at St Petersburg and Kaliningrad, will be increasingly isolated, only adding to the Kremlin's paranoia.
Finland and Sweden are joining Nato because Russia invaded Ukraine. That invasion was intended to push Nato further from Russia's borders. Instead, it has achieved the exact opposite.