BEIRUT, Lebanon — The Syrian capital of Damascus and its surrounding suburbs are entirely free of rebel fighters for the first time in seven years, the government said on Monday.

That milestone was achieved when the last Islamic State fighters reached an agreement with the government over the weekend to leave the Palestinian refugee camp of Yarmouk and the neighboring town of Hajar al-Aswad and head to one of the militant group’s last strongholds in eastern Syria.

Their retreat, confirmed by the Syrian Observatory for Human Rights, a monitoring group, ended weeks of fighting that had reduced the camp, once home to about 160,000, to smoking, dusty rubble.

After the final convoy of militants left, the government released a statement saying, “The Syrian General Command of the Army and Armed Forces announced Damascus and Damascus countryside entirely safe areas after fully cleansing al-Hajar al-Aswad and al-Yarmouk Camp of terrorism.”