TVER, Russia — Prime Minister Nikol Pashinyan of Armenia signed on Monday a Russian-brokered settlement to end the war in Nagorno-Karabakh, surrendering disputed territory and bowing to other demands as he faced a battlefield defeat.
The agreement signed by President Vladimir V. Putin of Russia, President Ilham Aliyev of Azerbaijan and Mr. Pashinyan calls for Armenia’s army to withdraw from the Nagorno-Karabakh region and to be replaced by Russian peacekeepers.
Under the deal, the warring sides were to halt fighting and prepare for the peacekeepers’ arrival. Three earlier cease-fires, negotiated by Russia, France and the United States, have collapsed.
But the agreement Monday suggested a more permanent, sweeping redrawing of the security map of the southern Caucasus, a volatile region wedged between Turkey, Russia and Iran. The settlement sealed a role in the region for an increasingly assertive Turkey, which backed Azerbaijan in the war that began in September.
“I personally made a very hard decision for me and all of us,” Mr. Pashinyan wrote in a statement announcing the agreement. “It’s not a victory, but there’s no defeat.”
Indeed, the agreement ends a quarter century of Armenian military control over the remote, mountainous region that is a touchstone of Armenian national identity. Russia will now guard the borders.
The Nagorno-Karabakh region has a mostly Armenian population but it fell within the Soviet-drawn borders of Azerbaijan. The enclave declared independence before the Soviet breakup.
For the Azerbaijanis, the settlement opens the prospect that at least some of the hundreds of thousands of internally displaced people who lost their homes in a separatist war that ended in 1994 could return to the region. That war ended with the shoe on the other foot: a cease-fire seen as catastrophic but inevitable for Azerbaijan after Armenian military victories.
Mr. Putin said the new agreement requires both the Armenian and Azerbaijani armies to stop at their currently occupied positions. That cements in place the Azerbaijani capture on Sunday of a strategic town, known as Shusha to Azerbaijanis and Shushi to Armenians. It is the second-largest town in the region and overlooks the separatist capital of Stepanakert, just about 6 miles away.
Armenia has also lost control of the access road needed for military supplies to reach the mountain enclave, starving its defenders of hope of holding out if the fighting continued.
“I made the decision as a result of a deep analysis of the military situation,” Mr. Pashinyan wrote. He said the deal was “the best solution in the situation.”
Within hours of the announcement, protests broke out in Yerevan, Armenia’s capital. A crowd broke into the government building and ripped Mr. Pashinyan’s nameplate off the door of the prime minister’s office, Russian television news showed.
“Where is Nikol? Where is that traitor?” the intruders screamed.
Mr. Putin said the agreement was “in the interests of the people of Armenia and Azerbaijan.”
For decades, Armenia had drawn support for its defense of the Nagorno-Karabakh region from a large diaspora in Southern California, France and Russia. Azerbaijan has relied on backing from Turkey, an ominous turn of events to Armenians who say the Turks have never accepted responsibility for atrocities committed during and after World War I. Distracted by the presidential election, the United States played only a limited role in the diplomacy over the past month.
The separatist government in Nagorno-Karabakh had for more than 25 years presided over seven occupied Azerbaijani districts outside the Soviet-era borders of the enclave. These were eerie, depopulated regions of deserted villages and ruined stone houses. Armenia defied United Nations resolutions calling for the return of the residents; holding, it seemed, the military advantage, the country had steadfastly refused any settlement allowing their return.
Now, the deal signed on Monday delivers to Azerbaijan much of what the country has sought for years in negotiations, including the return of internally displaced people.
Along with withdrawing its army from the enclave, Armenia agreed to surrender control of small ethnic Armenian areas inside Azerbaijan but not in Nagorno-Karabakh; to open a transport corridor for Azerbaijan through Armenia to the Azerbaijani region of Nakhichevan; and to allow the United Nations to oversee the return of the internally displaced people.
The capital of Nagorno-Karabakh, Stepanakert, was saved from what appeared to be imminent military attack but will rely on Russian peacekeepers for its defense.
The peacekeepers will deploy for five years and also guard the access road over a mountain pass known as the Lachin Corridor, and an approximately three-mile-wide buffer zone along its length, according to the agreement. Underscoring the loss of Shusha, or Shushi, the agreement calls for a new section of access road to be built around the now Azerbaijani-controlled town, a dramatic loss for the ethnic Armenian cause in Nagorno-Karabakh.