In this handout picture released by the Turkish Presidential press office, Turkey's President Recep Tayyip Erdogan (C) and invited guests attend Friday prayers at Hagia Sophia Grand Mosque during the buildings first official prayers after being reconverted into a mosque on July, 24, 2020 in Istanbul, Turkey. (Photo by Handout/Turkish Presidential Press Office/Getty Images)

Turkish President Recep Tayyip Erdogan joined thousands Friday in the first Muslim prayers in Hagia Sophia since the Istanbul landmark was controversially converted back into a mosque.

Massive crowds gathered inside and outside the UNESCO World Heritage site, some draped in Turkish flags and others waving Islamic banners.

Erdogan put their number at 350,000 but that figure could not be independently verified.

Some scuffles broke out between worshippers and police as crowds scrambled to get into the overcrowded plaza in the historic Sultanahmet district of Istanbul, where people had camped out the night before.

Inside, the faithful, wearing protective face masks, took photos as they waited for prayers to begin.

As the call to prayer reverberated from the Hagia Sophia’s four minarets, huge crowds spread prayer mats on the lawns outside.

Inside, the president, wearing an Islamic skullcap, recited a verse from the Koran.

In a sermon, the head of the state religious affairs agency, Ali Erbas, said the reopening “is the return of a sacred place, which had embraced believers for five centuries, to its original function.”

Also in attendance was Erdogan’s ally and leader of the ultranationalist MHP, Devlet Bahceli, but no opposition party leaders were present.

The Hagia Sophia was built as a cathedral during the Christian Byzantine Empire and converted into a mosque after the Ottoman conquest of Constantinople in 1453.

In 1934, modern Turkey’s founder Mustafa Kemal Ataturk ordered it be turned into a museum.

But Turkey’s highest administrative court, the Council of State, cancelled that decision earlier this month, arguing that the building had been registered as a mosque in its property deeds.

Experts see Erdogan’s move to turn Hagia Sophia back into a mosque as an attempt to galvanise his conservative and nationalist base amid economic uncertainty exacerbated by the virus outbreak.

The timing of the first prayer is significant as it coincided with the 97th anniversary of the Treaty of Lausanne, which set modern Turkey’s borders after years of conflict with Greece and Western powers.

Greece has condemned the move as a provocation to the “entire civilised world”.

“What is happening in (Istanbul) this day is not a show of force, but proof of weakness,” Greek premier Kyriakos Mitsotakis said in a statement.

“Especially to us Orthodox Christians, Hagia Sophia today is in our hearts more than ever. It is where our heart beats.”

One of the EU’s most senior officials warned that Ankara was undermining its ties with Europe.

“As a Greek, I’m quite bitter. I’m feeling quite angry about it,” European Commission vice-president Margaritis Schinas told a press briefing.

“I think that Turkey at a certain point should decide what their geopolitical stance should be, and who they want to align themselves with in the future,” warned Schinas, going further than the EU’s statements of concern to date.

“Will Turkey want to work along with the European Union and base themselves on European values? And, if that’s the case, what’s happening today with the Hagia Sophia is really a bad starting point.”

In Greece, church bells pealed at midday and flags were flown at half-mast as the head of the Church of Greece, Archbishop Ieronymos, described the conversion back into a mosque an “unholy act of defiling”.

Ankara has dismissed international criticism, and insisted that  tourists — some 3.8 million last year — would still be able to visit the mosque and see its famous Byzantine mosaics.

The mosaics, plastered over for centuries when the building served as a mosque, will now be hidden by curtains during prayer times since Islam bans figurative representations.

For many Muslims, the reconversion is nevertheless a landmark event.

“We see this as the second conquest of Istanbul,” said Selahattin Pamukcu, 33, who had come especially from the Aegean region of Izmir.

“This is the moment when Turkey breaks its chains. Now it can do whatever it wants, without having to submit to the West,” added Selahattin Aydas from Germany.