The annulment of a 1934 decision that had made the religious landmark a museum paved the way to the announcement, reports AP.
Meanwhile, the UNESCO, that declared the establishment as a world heritage site, called on Turkey to abide by its “legal commitments and obligations” in accordance with its status as a museum, on the World Heritage List.
Turkish President Recep Tayyip Erdogan has signed a decree handing control of the building over to the nation’s religious directorate, 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 cascading domes and four minarets. Dozens of people awaiting the court's ruling chanted "Allah is great!" when the news broke.
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.
He posted the decree on his Twitter account, with the words "may it be beneficial."
Erdogan had spoken in favor of turning the hugely symbolic UNESCO World Heritage site back into a mosque despite widespread international criticism, including from the United States and Orthodox Christian leaders, who had urged Turkey to retain its status as a museum as a symbol of solidarity among faiths and cultures.
The decision threatens to deepen tensions with neighboring Greece, whose culture minister, Lina Mendoni, denounced the move as "an open challenge to the entire civilized world that recognizes the unique value and universality of the monument."
"Hagia Sophia, located in Istanbul, is a monument to all mankind, regardless of religion," she said.
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."
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."
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."
"Russia is a country with the majority of the population professing Orthodoxy, and so, what may happen to Hagia Sophia will inflict great pain on the Russian people," he said in a statement.
U.S. State Secretary Mike Pompeo said last month the landmark should remain a museum to serve as bridge between faiths and cultures. His comments sparked 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 Quran 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.
Before the decision, UNESCO, the United Nations' cultural body, had called on Turkish authorities to engage in dialogue before taking any decision that might impact the site's "universal value."
UNESCO said it must be notified of any change to the status of Hagia Sophia, adding that changes may have to be reviewed by the World Heritage Committee.