BEIRUT — Syria’s government declared Thursday that it had regained full control of Aleppo after the last rebel fighters and civilians evacuated the key city as part of an agreement brokered by Russia and Turkey.

The Syrian military announced on state media that “security and stability” had been returned to eastern Aleppo, once the largest rebel stronghold. The “terrorists” — a term used by the Syrian government to describe nearly all of its opponents — had exited the city, the military said.

President Bashar Assad’s consolidation of Aleppo marks the end of the opposition presence in the city for the first time since 2012, in perhaps the most important battleground in the country’s raging civil war and a major blow to the rebellion to unseat Assad.

With crucial military and economic aid from Russia and Iran, Assad’s grip on power now looks much firmer compared with the uprising against him that erupted in 2011.

The Syrian leader and his allies are poised to consolidate their hold on areas of the country under their control and further squeeze the beleaguered rebellion elsewhere. His critics in the United States, Turkey and Saudi Arabia must increasingly grapple with a Syria, or at least major parts of it, that is now firmly under his control.

The foreign ministers of Russia, Iran and Turkey met in the Russian capital Tuesday to discuss ways to end the Syrian war, which has killed more than 400,000 people and displaced millions. On Thursday, Russia’s deputy foreign minister, Sergei Ryabkov, said in an interview with the RIA Novosti news agency that Assad’s future is “absolutely not a topic for discussion right now.”

Last week, pro-rebel residents of Aleppo began boarding buses to flee the war-ravaged eastern districts of the city as part of the Russia-Turkey deal that effectively surrendered their areas to Assad’s forces.

In frigid winter weather, desperate men, women and children waited in the thousands to be shuttled westward to the rebel-held Idlib province. The deal broke down multiple times as government-allied militia from Lebanon and Iran demanded similar evacuations from nearby Shiite villages besieged by rebel fighters.

“We left Aleppo with broken hearts,” Abu Jaafar, a 60-year-old father of five who was evacuated from eastern Aleppo, said.

U.N. officials said earlier Thursday that more than 40,000 people have been evacuated since Thursday, but the total number is unclear. Before the agreement, the United Nations estimated that about 250,000 people lived in eastern Aleppo.

For Syria’s armed opposition, Thursday’s events are a severe setback, if not an outright catastrophe.

As the final buses departed the snow-glazed ruins of eastern Aleppo late Thursday, rebel fighters expressed sadness. Some lashed out at the international community for what they said was insufficient support — especially weapons — to battle Assad and his powerful allies, including Iranian-controlled Shiite militia from Lebanon, Iraq and Afghanistan.

“All the world remained silent toward the crimes committed by the Russians, Iranians and 60 Shiite sectarian groups by not enabling rebels to obtain the means for defending themselves and their lands,” Lt. Col. Abu Bakr, a commander of the Jaish al-Mujahideen group that is part of the rebel umbrella Free Syrian Army, said. “This victory of Russia and Iran’s sectarian militias is over the ruins of a destroyed city.”

In 2012, rebel forces had triumphantly stormed the eastern districts of Aleppo and hoped to use the city as a staging ground for their eventual assault on the capital, Damascus, where they hoped to unseat Assad.

Instead, the war dragged on. Government allies, notably Iran and Russia, helped Assad gain the momentum. And in that time, residents of eastern Aleppo endured years of horrific bombardment from government and Russian warplanes that decimated hospitals, homes and entire families.

Zakaria Zakaria in Istanbul contributed to this report.