ANKARA, TURKEY -- The president of Turkey on Friday formally converted Istanbul's sixth-century Hagia Sophia back into a mosque and declared it open for Muslim worship, hours after a high court annulled a 1934 decision that had made the religious landmark a museum.

The decision sparked deep dismay among Orthodox Christians. Originally a cathedral, Hagia Sophia was turned into a mosque after Istanbul's conquest by the Ottoman Empire but had been a museum for the last 86 years, drawing millions of tourists annually.

There was jubilation outside the terracotta-hued structure with its cascading domes and four minarets. Dozens of people awaiting the court's ruling chanted “Allah is great!” when the news broke. A large crowd later prayed outside it.

In the capital of Ankara, legislators stood and applauded as the decision was read in Parliament.

Turkey's high administrative court threw its weight behind a petition brought by a religious group and annulled the 1934 Cabinet decision that turned the site into a museum. Within hours, President Recep Tayyip Erdogan signed a decree handing over Hagia Sophia to Turkey's Religious Affairs Presidency.

In a televised address to the nation, Erdogan said the first prayers inside Hagia Sofia would be held on July 24, and he urged respect for the decision.

“I underline that we will open Hagia Sophia to worship as a mosque by preserving its character of humanity's common cultural heritage,” he said, adding: “It is Turkey's sovereign right to decide for which purpose Hagia Sofia will be used.”

He rejected the idea that the decision ends Hagia Sophia's status as a structure that brings faiths together.

“Like all of our other mosques, the doors of Hagia Sophia will be open to all, locals or foreigners, Muslims and non-Muslims,” Erdogan said.

Erdogan had spoken in favour of turning the hugely symbolic UNESCO World Heritage site back into a mosque despite widespread international criticism, including from U.S. and Orthodox Christian leaders, who had urged Turkey to keep its status as a museum symbolizing solidarity among faiths and cultures.

The move threatens to deepen tensions with neighbouring Greece, whose prime minister, Kyriakos Mitsotakis, condemned the decision as an affront to Hagia Sophia's ecumenical character.

“It is a decision that offends all those who recognize Hagia Sophia as an indispensable part of world cultural heritage” Mitsotakis said. “This decision clearly affects not only Turkey's relations with Greece but also its relations with the European Union, UNESCO and the world community as a whole.”

In Greece's second-largest city, Thessaloniki, protesters gathered outside a church that is modeled on Hagia Sophia and bears the same name. They chanted, “We'll light candles in Hagia Sophia!” and held Greek flags and Byzantine banners.

Cyprus “strongly condemns Turkey's actions on Hagia Sophia in its effort to distract domestic opinion and calls on Turkey to respect its international obligations,” tweeted Foreign Minister Nikos Christodoulides.

Vladimir Dzhabarov, deputy head of the foreign affairs committee in the Russian upper house of parliament, called the action “a mistake.”

“Turning it into a mosque will not do anything for the Muslim world. It does not bring nations together, but on the contrary brings them into collision,” he said.

The debate hits at the heart of Turkey's religious-secular divide. Nationalist and conservative groups in Turkey have long yearned to hold prayers at Hagia Sophia, which they regard as part of the Muslim Ottoman legacy. Others believe it should remain a museum, as a symbol of Christian and Muslim solidarity.

“It was a structure that brought together both Byzantine and Ottoman histories,” said Zeynep Kizildag, a 27-year-old social worker, who did not support the conversion. “The decision to turn it into a mosque is like erasing 1,000 years of history, in my opinion.”

Garo Paylan, an ethnic Armenian member of Turkey's Parliament tweeted that it was “a sad day for Christians (and) for all who believe in a pluralist Turkey.”

“The decision to convert Hagia Sophia into a mosque will make life more difficult for Christians here and for Muslims in Europe,” he wrote. “Hagia Sophia was a symbol of our rich history. Its dome was big enough for all.”

The group that brought the case to court had contested the legality of the 1934 decision by the modern Turkish republic's secular government ministers, arguing the building was the personal property of Ottoman Sultan Mehmet II, who conquered Istanbul in 1453.

“I was not surprised at all that the court weighed to sanction Erdogan's moves because these days Erdogan gets from Turkish courts what Erdogan wants,” said Soner Cagaptay, of the Washington Institute.

“Erdogan wants to use Hagia Sophia's conversion into a mosque to rally his right-wing base,” said Cagaptay, the author of “Erdogan's Empire.” “But I don't think this strategy will work. I think that short of economic growth, nothing will restore Erdogan's popularity.”

In Paris, the United Nations cultural body, UNESCO, said Hagia Sophia is part of the Historic Areas of Istanbul, a property inscribed on UNESCO's World Heritage List as a museum.

“States have an obligation to ensure that modifications do not affect the `outstanding universal value' of inscribed sites on their territories,” Director-General Audrey Azoulay said.

The Istanbul-based Ecumenical Patriarch Bartholomew I, considered the spiritual leader of the world's Orthodox Christians, warned last month that the building's conversion into a mosque “will turn millions of Christians across the world against Islam.”

On Friday, Archbishop Elpidophoros of America said the decision runs counter to the vision of secular Turkey's founder, Mustafa Kemal Ataturk “who understood that Hagia Sophia should serve all Turkey's people and indeed the whole world.”

“The days of conquest should remain a closed chapter of our collective histories,” he told The Associated Press, adding that Turkey's government “can still choose wisely” but letting Hagia Sophia remain a “monument to all civilizations and universal values.”

Patriarch Kirill, the leader of the Russian Orthodox Church, called for “prudence” and the preservation of the “current neutral status” for the Hagia Sophia, which he said was one of Christianity's “devoutly venerated symbols.”

U.S. Secretary of State Mike Pompeo said last month that the landmark should remain a museum to serve as bridge between faiths and cultures. His comments drew a rebuke from Turkey's Foreign Ministry, which said Hagia Sophia was a domestic issue of Turkish national sovereignty.

Erdogan, a devout Muslim, has frequently used the Hagia Sophia issue to drum up support for his Islamic-rooted party.

Some Islamic prayers have been held in the museum in recent years. In a major symbolic move, Erdogan recited the opening verse of the Qur'an there in 2018.

Built under Byzantine Emperor Justinian, Hagia Sophia was the main seat of the Eastern Orthodox church for centuries, where emperors were crowned amid ornate marble and mosaic decorations.

The minarets were added later, and the building was turned into an imperial mosque following the 1453 Ottoman conquest of Constantinople - the city that is now called Istanbul.

The building opened its doors as a museum in 1935, a year after the Council of Ministers' decision.

Mosaics depicting Jesus, Mary and Christian saints that were plastered over in line with Islamic rules were uncovered through arduous restoration work for the museum. Hagia Sophia was the most popular museum in Turkey last year, drawing more than 3.7 million visitors.

------

Associated Press writers Zeynep Bilginsoy and Ayse Wieting in Istanbul, Derek Gatopoulos in Athens, Menelaos Hadjicostis in Nicosia, Cyprus, and Jim Heintz in Moscow contributed.