BEIRUT — Carrying their rifles and small bags of belongings, hundreds of exhausted Syrian rebels withdrew Wednesday from their last remaining strongholds in the heart of Homs, surrendering to President Bashar Assad a bloodstained city that was once the center of the revolt against him.

For Assad, it is a powerful victory ahead of presidential elections. For the rebels, the dramatic exit after two years of enduring grueling assaults and siege captures their sense of abandonment amid world reluctance to help shift the balance of power on the ground.

“We ate grass and leaves until there was nothing left for us to eat,” said opposition activist Abu Yassin al-Homsi, who was preparing to leave with the rebels later Wednesday. “We kept urging the international community to lift the siege but there was no response,” he added.

The exit of some 1,200 fighters and civilians marks a de facto end of the rebellion in the war-shattered city, which was one of the first places to rise up against Assad’s rule, earning its nickname as “the capital of the revolution.”

Gaining virtually full control of Syria’s third largest city is a major win for Assad on multiple levels. Militarily, it solidifies the government hold on a swath of territory in central Syria, linking the capital Damascus with government strongholds along the coast and giving a staging ground to advance against rebel territory further north.

Politically, gains on the ground boost Assad’s hold on power as he seeks to add a further claim of legitimacy in presidential elections set for June 3, which Western powers and the opposition have dismissed as a farce.

“For those who want to believe that the regime is winning, it’s a powerful symbolic confirmation of that,” said Peter Harling, a Middle East expert at the International Crisis Group think tank. “But it really is about what the regime has to offer beyond years of such symbolic military victories,” he added.

“If you take a broader perspective, I think it’s an indication that this conflict is going to take years.”

By early evening Wednesday, some 600 fighters had boarded buses that departed from a police command center on the edge of Homs’ rebel-held areas, heading north to rebel held towns of Talbiseh and al-Dar al-Kabira, opposition activists said.

Many rebels were wounded; it was unclear how many civilians were among them.

According to the deal, each fighter was allowed to carry his rifle and a bag of belongings. One rocket propelled grenade launcher and a machine gun were also allowed on each bus.

“We shall return to Homs!” some of the evacuees chanted as they arrived in al-Dar al-Kabria and residents rushed to give them fruits and water, according to Mohammed Rahal, an activist who was there to receive them. He said some of the fighters were “so weak they needed assistance to walk.”

Videos of the evacuation posted online by activists captured the massive destruction inflicted on Homs from months of bombardment. Buildings were shattered, some with chunks of concrete dangling from twisted rebar, others with upper floors collapsed.