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, russias 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 azerbaijans 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.

Armenias 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, azerbaijans president ilham aliyev said in a speech: well get our lands back, either through peace or war . . . we want to do it peacefully. were 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 azerbaijans 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.

Additional reporting by laura pitel in ankara.