The ambassador in Tehran and his staff left after being informed of "concrete and serious threats against the ambassador", the Danish foreign ministry said in a communique on Saturday.
Finland's embassy in Iran has taken charge of Denmark's consular affairs until further notice.
In Jakarta, the ambassador and his aides left after receiving "credible and concrete threats against the security of embassy personnel" and the Dutch embassy will provide consular cover.
Lars Thuesen, spokesman for the ministry's crisis unit, said the ambassadors and their staff had gone to other countries, which Denmark did not wish to identify.
The building housing the embassy in Damascus was burnt last week by an angry mob protesting against the Prophet Muhammad cartoons first published in a Danish newspaper.
The foreign ministry said it has been pulling out Danish staff since then, and the ambassador left on Friday.
"The de-escalation of the protection of the ambassador and his staff to an inadequate level is the reason for the departure," the ministry said in a statement.
Denmark closed its mission in
Lebanon earlier this week
It said the German embassy in Damascus would handle Denmark's consular services for the time being.
Sweden, which has its embassy in the same building in the Syrian capital, did not have any immediate plans to withdraw staff, said Jan Janonius, a spokesman for the foreign ministry in Stockholm.
Denmark temporarily closed its diplomatic mission in Lebanon earlier this week after similar protests there.
The small Scandinavian country is shell-shocked by the wave of anti-Danish protests, some of them violent, that have spread like wildfire across the Muslim world.
Danish paper Jyllands-Posten, which published the cartoons in September, apologised for offending Muslims but stood by its decision to print the drawings, citing the freedom of speech.
Islam forbids any illustrations of Muhammad.