A Syrian army soldier places a Syrian national flag during a battle with rebel fighters at the Ramouseh front line, east of Aleppo, Syria, on Dec. 5, 2016. (Hassan Ammar/AP)

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 al-Assad’s consolidation of Aleppo marks the end of the opposition presence in the city for the first time in more than four years and deals a major blow to the rebellion to unseat him.

Assad now appears to have the upper hand in the conflict, which began with protests against him 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 a major portion 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 city’s war-ravaged eastern districts 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 rebel-held Idlib province. The deal broke down multiple times as government-allied militias from Lebanon and Iran demanded similar evacuations from nearby Shiite villages besieged by rebel fighters.

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

U.N. officials said earlier Thursday that more than 40,000 people had been evacuated , but the total number is unclear. Before the agreement, the United Nations estimated that 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 militias 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,” said Lt. Col. Abu Bakr, a commander of the Jaish al-Mujahideen group that is part of the rebel umbrella Free Syrian Army. “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 momentum, and 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.