Azerbaijanis celebrated the signing of a deal early Tuesday ending the longstanding conflict over Upper Karabakh, also known as Nagorno-Karabakh.

They took to the streets after President Ilham Aliyev described the agreement reached to halt fighting over the region as the defeat of Armenia.

In his televised address, Aliyev said Agdam District will be delivered to Baku as of Nov. 20 while Kalbajar will be returned by Nov. 15 and Lachin by Dec. 1.

The capital Baku was the scene of enthusiastic celebrations despite the early hour, with thousands of people carrying both Azerbaijani and Turkish flags.

Some Azerbaijanis danced in the streets while others celebrated in convoys of cars.

Some cried out of happiness and others sang songs and the national anthem.

In Ganja, the second-largest city in the country, people also celebrated.

Hundreds of people gathered in Ganja’s main square carrying Azerbaijani and Turkish flags.

Speaking to Anadolu Agency, a local resident, Elnur Habiboglu, expressed her joy.

“We are returning to our own lands hopefully after 28 years,” Habiboglu said.

“Azerbaijan and Turkey are one nation with two states.”

Another local, Sefika Fazil, said her brother was a soldier.

“Thank you very much. Turkey and Azerbaijan are brothers. We have won together.”

Russian President Vladimir Putin announced earlier in the day that Azerbaijan and Armenia had signed the agreement.

Relations between the two former Soviet republics over Upper Karabakh have remained tense since 1991, but fresh clashes broke out on Sept. 27.

Since then, Armenia has repeatedly attacked Azerbaijani civilians and forces, even violating three humanitarian cease-fire agreements.

About 20% of Azerbaijan's territory has been under illegal Armenian occupation for nearly three decades.