The Moscow-brokered agreement, which saw a cease-fire take effect at 1:00 a.m. local time (2100 GMT), came after a string of Azerbaijani victories in its fight to retake the ethnic Armenian enclave, AFP reported.
It sparked celebrations in Azerbaijan but fury in Armenia, where protesters took to the streets to denounce the country's leadership for losses in the territory, which broke from Azerbaijan's control during a war in the early 1990s.
Armenian Prime Minister Nikol Pashinyan, Azerbaijani President Ilham Aliyev and Russian President Vladimir Putin announced the deal in the early hours of Tuesday.
Pashinyan described the agreement as "unspeakably painful for me and for our people", while Aliyev said it amounted to a "capitulation".
The full text of the deal was released several hours later and showed clear gains for Azerbaijan.
Its forces will retain control over areas seized in the fighting, including the key town of Shusha, while Armenia agreed to a timetable to withdraw from large parts of Nagorno-Karabakh.
A Russian force of 1,960 military personnel and 90 armored personnel carriers will deploy to the region as peacekeepers, for a renewable five-year mission.
The Russian Defense Ministry said Tuesday that 10 Il-76 aircraft carrying the first peacekeepers and their equipment had taken off from an airfield in Russia.
Aliyev said that Turkey, a key ally, would also be involved in peacekeeping efforts but there was no mention of it in the agreement.
Armenian Defense Ministry spokeswoman Shushan Stepanyan said on Twitter that the situation was calm in the region at 6:00 a.m. local time and that "combat operations on the whole frontline are suspended".
The conflict over the territory – which has simmered for decades despite international efforts to reach an accord – erupted into fresh fighting in late September.
More than 1,400 people have been confirmed killed, including dozens of civilians, but the actual death toll is believed to be significantly higher.
Azerbaijani forces made steady gains over the weeks of fighting, sweeping across the southern flank of the region and eventually into its heartland.
A turning point came on Sunday when Aliyev announced that his forces had captured Shusha, the region's strategically vital second-largest town.
Anger in Armenia
Shusha sits on cliffs overlooking Nagorno-Karabakh's main city Stepanakert and on the main road to Armenia, which backs the separatists.
Armenian officials had initially denied the town had been taken and the announcement of the deal caused outrage, with angry protesters storming the government headquarters in the capital Yerevan where they ransacked offices and broke windows.
Crowds also entered Parliament and demanded Pashinyan's resignation.
Police had retaken control of both buildings on Tuesday but there were calls for demonstrations against Pashinyan, who came to power leading a wave of peaceful protests in 2018.
In the Azerbaijani capital Baku joyful residents took to the streets chanting "Karabakh! Karabakh!"
Karabakh declared independence nearly 30 years ago but the declaration has not been recognized internationally, even by Armenia, and it remains a part of Azerbaijan under international law.
Attempts at cease-fires brokered by France, Russia and the United States – who together lead the Minsk Group that sought for years to end the conflict – repeatedly failed over recent weeks.
The agreement announced Tuesday made no mention of the status of the Armenian-populated areas of Nagorno-Karabakh or of the format of future negotiations to settle the conflict.
The cease-fire deal came just hours after Azerbaijan admitted to accidentally shooting down a Russian military helicopter flying in Armenia near Nakhchivan.