A new "memorandum of understanding" between the three countries seeks to allay Turkish fears over security.
Finland and Sweden have struck a deal with Turkey that sees Ankara drop its objections to the two Nordic countries joining NATO.
In a statement, Turkish President Erdogan said he had obtained “full cooperation” from Finland and Sweden against Kurdish PKK fighters and their allies, after more than three hours of discussions on Tuesday in Madrid, on the sidelines of the NATO summit.
After the talks, NATO Secretary-General Jens Stoltenberg said “we now have an agreement that paves the way for Finland and Sweden to join NATO.”
Russian President Vladimir Putin "is getting more NATO on his borders", the alliance chief said.
"So what he gets is the opposite of what he actually demanded, and that was to NATO to close its doors. We are demonstrating that NATO's doors are open. NATO's door is open."
"As a result of that meeting, our foreign ministers signed a trilateral memorandum which confirms that Turkey will at the Madrid Summit this week support the invitation of Finland and Sweden to become members of NATO," Finland's President Sauli Niinistö said in a statement released by his office.
"One step forward," Niinistö later wrote on his personal Twitter account.
Finnish Minister of Defence Antti Kaikkonen said: "Today saw the power of diplomacy and negotiation."
"There is still a long way to go, but we are going there," he added.
What were the issues Turkey raised?
Turkey had raised a laundry list of grievances with Finland and Sweden which they wanted to be cleared up before agreeing to lift their block on NATO membership.
And it seems the two Nordic nations have given in to Turkish demands, which included preventing recruitment, fundraising, and propaganda activities of the Kurdish PKK group.
Turkey also wanted the extradition of more than 30 people by Finnish and Swedish authorities -- some are alleged PKK activists, while others are alleged members of the so-called Gülenist movement which Erdogan believes was behind a 2016 attempt to overthrow him.
Turkey said it had “got what it wanted” including “full cooperation [...] in the fight against” the rebel groups.
"Finland and Sweden, of course, are ready to work with Turkey on the pending deportations or extradition requests of terror suspected individuals," NATO Secretary General Jens Stoltenberg said.
"But at the same time that this extradition process will take place in accordance with the European Convention on Extradition, I mean, this is, of course, in respect of the rule of law, the legal systems in these countries."
The latest opinion polling in Finland, released on Monday, showed little appetite to give in to Turkish demands ahead of the NATO summit.
A survey for Helsingin Sanomat newspaper found a clear 70% of Finns don't think there should be any change in legislation, or a change in principles, to appease Turkey.
Only 14% thought Finland should accede to the Turkish demands.
The toughest position on Turkey was taken by supporters of the Greens and Left Alliance political parties, while far-right Finns Party supporters were the most willing to make concessions.
The same poll found that 79% of Finns are now in favour of NATO membership -- a record high since polling first began on this subject more than two decades ago -- with 10% against joining NATO, and 11% unsure.