After three years of brutal fighting, Syrian rebels have evacuated the last of their troops from Homs, a strategically important city that had been a symbol of resistance against four decades of rule by the Assad regime.

The retreat comes after opposition leaders and government security officials, with the help of Iran’s ambassador to Damascus, made a deal that would give the Syrian military control of the city and allow rebels associated with the Free Syrian Army, and their families, to evacuate safely. The deal is the first sign of talks between the opposition and military since the civil war began three years ago.

The loss of the city to military forces, while not necessarily a setback in operational terms, is a crushing blow to the morale of rebel troops who had long thought of Homs as the “capital of the revolution.”

As many as 2,500 people have been trapped in Homs since the Syrian military created a blockade around the ancient city in 2012, prohibiting aid groups and U.N. workers from entering. The military stepped up its offensive in recent weeks, forcing the rebels to consider the deal.

Videos posted on YouTube show U.N. vehicles leading busloads of families out of the city. After years of bombing, Homs is now completely hollowed out, its buildings crumbling and pockmarked by sniper fire.

According to the Syrian Observatory on Human Rights, two buses have left Homs and are headed toward Dar al-Kabira, a town in the countryside to the north. Once the buses reach the city, a group of hostages and prisoners held by the rebels in Nabbul and al-Zahraa will be released. The deal will also allow humanitarian groups to deliver aid to Homs.

Although protests in the southern city of Dara’a in March 2011 marked the beginning of the uprising in Syria, it was the demonstrations in Homs the following month that brought the conflict to a new level. Clashes between security forces and protesters in Homs intensified and what started out as peaceful demonstrations quickly turned into armed resistance.

Sunni rebels in the city organized themselves to fight President Bashar Assad’s forces. Members of Assad's Alawite sect of Islam, a Shia offshoot, left the city in fear that the Sunni-led resistance would target them. In the 1960s and ‘70s, Alawites migrated from the coastal mountains to areas such as Homs. Since the beginning of the conflict, many Alawite families have moved back to historically Alawite-majority communities like Latakia and Tartus, fearing slaughter by the Sunnis.

Homs, the third-largest city in Syria, is located in the western part of the country near the Lebanese border and sits in the middle of the north-south highway between Aleppo and Damascus. The highway is the main line of communication between the country’s two most populous cities and economic centers. The city also has several key oil refineries, and has been a hotbed for violence throughout the three-year conflict.

Homs fell in and out of the hands of the rebels throughout the conflict. Whereas the opposition has secured areas around Aleppo province in the north, Homs has been an area of constant turmoil and uncertainty.

The rebels and military focused most of their fighting in the city district of Baba Amr. The opposition lost control of the area in March 2012, in a battle widely reported in Western media in which journalist Marie Colvin of the Sunday Times and French photographer Remi Ochlik were killed. Since then, the armies have struggled block-by-block for control of neighborhoods.

Both sides were accused of committing atrocities. In March 2012 opposition activists said that soldiers had rounded up civilians in Homs and killed dozens of them, including women and children. The government denied the accusations. Allegations of war crimes from both sides have circulated throughout the conflict, but because of limited access since the military blockade of Homs in 2012, it is impossible to confirm the accounts.