BAKU - In an agreement brokered by Russia, Azerbaijan won many of the concessions it has sought for decades in negotiations over the Nagorno-Karabakh separatist region.

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.

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.