Armenia and Azerbaijan have agreed to a limited ceasefire in their conflict for control of the disputed territory of Nagorno-Karabakh, after marathon talks brokered by Moscow to pause almost two weeks of fighting.

Both countries’ foreign ministers agreed to a humanitarian ceasefire beginning at 12 midday on Saturday to exchange the bodies of those killed and prisoners of war, Russia’s foreign minister Sergei Lavrov said in a statement after 10 hours of talks in Moscow that ended at 3am.

The truce is the first breakthrough in efforts to halt the worst outbreak in fighting between the two neighbours since a 1994 war over the territory that killed 30,000 people.

Mr Lavrov said that the International Committee of the Red Cross would mediate the exchanges, but admitted that the “specific parameters of the ceasefire regime will be agreed upon additionally.”

The mountainous region of Nagorno-Karabakh is part of Azerbaijan but is populated and controlled by ethnic Armenians with the support of Yerevan. Russia has been under increased pressure to find a way to end the fighting, which has killed hundreds and displaced tens of thousands of people since late September.

But Moscow has found its geopolitical dominance over the confilct in the post-Soviet countries eroded by strong support of Baku by Turkey, which opposed calls from Russia, France and the US for ceasefire talks.

If the ceasefire is successful it would mark a diplomatic victory for the Kremlin which has good relations with both countries and is loath to intervene militarily. Russia has a military base in Armenia and a mutual defence pact with the country, although that does not extend to Nagorno-Karabakh.

In a sign of how difficult any subsequent peace talks will be, Armenia on Saturday reiterated its opposition to any role in those talks for Turkey, while Ankara repeated its backing for Azerbaijan’s stated aim of recovering the territory.

Ankara said that Azerbaijan had agreed to the ceasefire “in order to give Armenia a last chance to withdraw from the lands that it is occupying”. The Turkish foreign ministry said that, in the latest bout of fighting, Azerbaijan had “shown the whole world that it is capable of reclaiming lands that have been occupied for 30 years with self-confidence and with its own means”. It said that Turkey would continue to stand in support of Baku “at the negotiating table and on the battlefield”.

Armenia’s president Armen Sarkissian told the Financial Times ahead of the talks that Russia needed to do more to end the fighting and end the involvement of Turkey, which he described as “the bully of the region.” As the mediation talks began, Azerbaijan’s president Ilham Aliyev said in a speech: “We’ll get our lands back, either through peace or war . . . We want to do it peacefully. We’re giving Armenia one last chance.”

Mr Lavrov said that both sides had agreed to “begin substantive negotiations with the aim of reaching a peaceful settlement as soon as possible.” Armenia and Azerbaijan’s foreign ministers did not speak to the press after the meeting concluded.

Both sides are accused of shelling civilian areas during the 12 days of fighting, which has been marked by the use of drones and heavy artillery.