About 50 UN staff and aid workers have been evacuated from the western Afghan city of Herat following clashes between troops and angry demonstrators.
Calm is reported to have been restored to Herat
At least seven people died as protests against the sacking of Herat's powerful governor, Ismail Khan, turned violent.
An overnight curfew was lifted and the city was reported to be calm again.
The man appointed to replace Mr Khan as governor of Herat, Mohammed Khair Khuwa, has said restoring security is his first priority.
Most of the hundreds of Afghan army troops deployed in the city centre on Sunday were pulled back by Monday morning, although US helicopters were still patrolling above, the BBC's Andrew North says.
The new governor will have to contend with continued significant support for Mr Khan in the city, and the question of whether he will start disarming the militia force he controls, our correspondent adds.
However, Iran, which has close links to the sacked governor, said it accepted the dismissal, and would not attempt to interfere in Afghanistan in the run-up to next month's elections.
During Sunday's violence, UN staff had to be helped to safety by US and government troops after hundreds of demonstrators attacked their offices.
They ransacked the compound - which houses the offices of the UN High Commissioner for Refugees and the UN Assistance Mission - setting fire to parts of the buildings and throwing stones.
Troops tried to keep back the crowds with tear gas.
Foreign and local workers from the UN and other aid agencies headed for Herat's airport on Monday, having spent the night at a US base in the city.
Our correspondent says the UN withdrawal comes at a bad time as staff were due to help organise elections on 9 October.
The disturbances broke out after Afghan President Hamid Karzai sacked Mr Khan, in line with his election pledge to rein in warlords.
Mr Khan, one of the best-known former mujahideen leaders, had ruled Herat for years and has resisted the president's authority.
At least 60 people, including 15 US troops, were reportedly wounded.
UN Secretary General Kofi Annan condemned the violence, but said the UN remained committed to providing humanitarian and reconstruction assistance in Afghanistan.