Azerbaijan and Armenia said they were halting hostilities after four days of intense fighting between them that had prompted warnings the conflict could spiral into all-out war.

In a statement on the ceasefire, Azerbaijan's defence ministry said: "On April 5 at 12:00 (0800 GMT), on the basis of a mutual agreement, military actions on the contact line between the armed forces of Armenia and Azerbaijan are halted."

An official with the Armenian-backed armed forces of Nagorno-Karabakh told the Reuters news agency: "We've been ordered to halt fire."

Talks aimed at ending the worst violence for decades in the disputed territory of Nagorno-Karabakh had started in Vienna on Tuesday after 46 people were killed in three days of fighting.

Russia and the US have called for the fighting to end but Turkey is standing by Azerbaijan, and predicts the territory its ally has lost will "one day" be recovered.

A landlocked mountainous region with an ethnic Armenian majority lying within Azerbaijan, Nagorno-Karabakh has been in dispute since the collapse of the Soviet Union in 1991.

WATCH: What triggered the conflict?

Separatists backed by Yerevan announced allegiance to Armenia and then declared an independent republic, a move that has not been recognised elsewhere, including by Armenia.

In the subsequent fighting, around 30,000 lives were lost and thousands of people from both ethnic groups fled their homes.

A ceasefire brokered by Russia was signed in 1994, but the two countries have never agreed on a lasting peace.

Azerbaijan announced a unilateral truce on Sunday, but it failed to stop the fighting, and on Monday Armenia said a ceasefire would be possible only if both sides return to their previous positions.

Azerbaijan's defence minister Zakir Hasanov instead ordered the army to be ready to strike Karabakh's self-declared capital Stepanakert "in case of continued Armenian bombardment of civilian targets in Azerbaijan".

Hundreds of ethnic Armenian volunteers have since headed to the city to fight alongside separatist forces, while local authorities have been busy organising shelters for the refugees from frontline villages.