Armenia on Tuesday signed an "unspeakably painful agreement" with Azerbaijan to temporarily end the dispute over Nagorno-Karabakh.

The signing of the peace agreement came only hours after Azerbaijan seized the region's strategic city of Shusha. The loss of Shusha makes it militarily untenable for Armenia to hold on to Stepanakert, the region's largest city.

In addition, Armenian separatist forces have steadily lost territory to Azerbaijan since fighting erupted Sept. 27.                             

"I have made a difficult, extremely difficult decision for me personally and all of us. I have signed a declaration with the leaders of Russia and Azerbaijan on stopping the war starting from 01:00 (local time)," Armenian Prime Minister Nikol Pashinyan said.

Pashinyan said his decision was based on "deep analyses of the combat situation and in discussion with best experts of the field."

"This is not a victory but there is not defeat until you consider yourself defeated," Pashinyan, who first made the announcement on Facebook early Tuesday morning, said.

Armenian leader in Nagorno-Karabakh, Arayik Harutyunyan, said he agreed "to end the war as soon as possible." Russian President Vladimir Putin confirmed details of the deal, brokered by Moscow, minutes later in a televised statement.

The agreement came into effect at 21:00 GMT, or a few minutes before Pashinyan made the announcement. The deal was met with angry demonstrations in Yerevan, the Armenian capital and throughout the country.

It orders "the complete cessation of hostilities in Nagorno-Karabakh," according to Putin.

Armenia and Azerbaijan will maintain their current territorial positions as part of the deal. This means Azerbaijan will retain possession of the ground it captured since the start of the conflict.

On the other hand, Armenia will return other occupied territories which it currently controls in phases the next month.

The peace deal will return to Azerbaijani control of seven districts surrounding the Nagorno-Karabakh region Armenia seized during the 1988 to 1994 conflict. The religiously important city of Shusha, which is also called "the Jerusalem of Nagorno-Karabakh," will fall under Azeri control.

The terms of the peace deal, which means a significant loss of territory in Nagorno-Karabakh, confirm Armenia's military defeat.

Armenia, however, will retain control over most of Nagorno-Karabakh itself. Hundreds of thousands of Azeri refugees and internally displaced persons from the previous war will be permitted to return to Nagorno-Karabakh, said Azeri President Ilham Aliyev.

Aliyev said the deal will "return our territories without any further bloodshed." He said all military operations in the region inside Azeri territory but populated and controlled by ethnic Armenians have stopped.

"Today, I am signing this agreement with pride! Congratulations to the people of Azerbaijan!" said Aliyev.

A Russian peacekeeping force consisting of 2,000 men will be deployed for a minimum of five years to protect the land corridor between Armenia and the Nagorno-Karabakh region.

Azerbaijan will gain passage to Nakhchivan, which is detached from Azerbaijan by a strip of Armenian land close to the border with Turkey and Iran. Russian forces will guarantee access to the roads connecting Azerbaijan and Nakhchivan. Putin expects the agreement "will create the conditions for a long-term settlement.