NATO’s top official said Tuesday that Turkey had dropped its objections to the membership of Sweden and Finland, two historically nonaligned nations that, alarmed by Russia’s invasion of Ukraine, have asked to join the military alliance.

Turkey’s reversal is a blow to President Vladimir V. Putin, who in justifying the invasion of his neighbor bitterly protested previous expansions of NATO — and Ukraine’s efforts to join the alliance — as a threat to his country’s security.

Should Finland and Sweden be formally adopted into the alliance, as is widely expected, Russia will look across 800 miles of border with Finland at one of NATO’s newest members.

The announcement came after Turkey’s president, Recep Tayyip Erdogan, met for four hours with Prime Minister Magdalena Andersson of Sweden and President Sauli Niinisto of Finland, as NATO heads of state gathered in Madrid for an annual summit. The 30-nation alliance operates by consensus, which meant that Turkey effectively held a veto over their membership applications.

“I’m pleased to announce that we now have an agreement that paves the way for Finland and Sweden to join NATO,” the secretary-general, Jens Stoltenberg, said Tuesday evening. “Turkey, Finland and Sweden have signed a memorandum that addresses Turkey’s concerns, including around arms exports, and the fight against terrorism.”

It was not clear what concessions, if any, were made to Mr. Erdogan, whose objections centered on the quest for autonomy by ethnic Kurds in Turkey and neighboring countries. He has accused Sweden and Finland of sheltering Kurds whom Turkey calls terrorists, and he objects to the embargo on arms sales that the Scandinavian countries placed on Turkey after its incursion into Syria to fight Kurdish forces.

The announcement came on a day when Western and Russian leaders, jockeying for the upper hand, made rival diplomatic pushes as Moscow’s military forces pursued their brutal campaign against Ukraine.

The NATO heads of state will agree to strengthen forces along the military alliance’s eastern flank, and President Biden, who strongly supported NATO membership for Finland and Sweden, planned to announce the deployment of two additional Navy destroyers to a base in Rota, in the south of Spain. The meeting is scheduled to continue through Thursday.

“By the end of the summit,” declared Jake Sullivan, the U.S. national security adviser, “what you will see is a more robust, more effective more combat-credible, more capable, and more determined force posture.”

But as Western leaders met in Madrid, after concluding a Group of 7 meeting in Germany that was also dominated by the invasion of Ukraine, Mr. Putin engaged in his own diplomatic offensive.

Making his first trip abroad since the Russian invasion began on Feb. 24, Mr. Putin visited Tajikistan, where he was embraced on the tarmac by its president, Emomali Rahmon. With the Kremlin keen to preserve its influence in Central Asia as it becomes increasingly isolated from the West, Mr. Putin also planned to attend a summit of regional leaders in Turkmenistan, an insular, gas-rich former Soviet republic on the Caspian Sea.

“In general, an atmosphere of friendship and cooperation reigns in the Caspian,” Mr. Putin’s foreign policy adviser, Yuri V. Ushakov, told reporters on Monday, according to Russian news agencies.

G7 leaders, acknowledging that their efforts to punish Moscow have to date had little effect on the war, agreed to pursue a plan aimed at undercutting Russia’s oil revenue. And with millions around the world facing acute hunger, the leaders also pledged to spend $4.5 billion this year to help ensure food security, seeking to counter grain shortages caused by the invasion.

In Ukraine on Tuesday, as workers combed the rubble of a shopping mall in the city of Kremenchuk that was destroyed in a Russian missile strike a day earlier — the death toll was raised to 18, with dozens injured and 21 still missing — Moscow pressed its bombardment of civilian targets across the country, Ukrainian officials said.

From the southern Ukrainian port city of Mykolaiv to the northeastern reaches near Kharkiv, Ukrainian officials reported more Russian missile and bombing strikes overnight. At least eight civilians, including a 6-year-old girl, were killed and dozens wounded, including a 3-month-old baby who was in a coma.

Vitaly Kim, head of the Mykolaiv regional military administration, said Tuesday that Russia had launched at least 11 missiles on targets in the region, and that while several had been shot down by air defense systems, others got through. Russians also shelled the small town of Ochakiv, on the Black Sea coast just east of the port city of Odesa, killing three people, Mr. Kim said.