Turkey President Recep Tayyip Erdogan attended the first prayer service at the Hagia Sophia in over 86 years.

Thousands gathered from across Turkey to attend the service – the first since Erdogan repealed Hagia Sophia’s status as a museum. Areas outside of the building were sectioned off for prayer, quickly filling to capacity.

As many as 350,000 people took part in the prayer, with many in attendance wearing face masks as a precaution during the coronavirus pandemic.

Faithful wait at the historic Sultanahmet district of Istanbul, outside the Byzantine-era Hagia Sophia, Friday, July 24, 2020. (AP Photo/Yasin Akgul)

Erdogan started the prayer with a recitation of the Quran, then handed the service over to Ali Erbas, who prayed that Muslims would never again be “denied” the right to worship at Hagia Sophia.

POPE FRANCIS SAYS HE IS 'DEEPLY PAINED' OVER TURKEY'S DECISION ON HAGIA SOPHIA

Built nearly 1,500 years ago, Hagia Sophia was the first cathedral in the Roman Empire. After a thousand years, the Ottomans converted the structure into a mosque following the sack of Constantinople.

When national hero Mustafa Kemal Ataturk established the modern state of Turkey, he converted the mosque into a museum, a move that was in line with his secular policy for the new country.

Faithful wait at the historic Sultanahmet district of Istanbul, near the Byzantine-era Hagia Sophia, Friday, July 24, 2020. (AP)

The decision to reopen the Byzantine structure as a mosque drew criticism from Greece, the United States and Christian church leaders who called on Erdogan to maintain the museum status of Hagia Sophia, but the president finalized the move following a high court order.

“This is Hagia Sophia breaking away from its captivity chains. It was the greatest dream of our youth,” Erdogan said last week. “It was the yearning of our people and it has been accomplished.”

Muslims pray during Friday prayers at the historic Sultanahmet district of Istanbul, near the Byzantine-era Hagia Sophia, background, Friday, July 24, 2020. (AP Photo/Yasin Akgul)

Some believe that Erdogan has pushed through the move in order to combat his sagging popularity during an economic downturn.

SAUDI OFFICIALS GO ON TRIAL IN ABSENTIA IN TURKEY FOR KHASHOGGI MURDER

“It allows him to switch the narrative away from the economy to the culture wars, an area where he did well in the past by mobilizing his right-wing base,” said Soner Cagaptay, Turkey analyst for the Washington Institute and author of “Erdogan’s Empire,” told The Associated Press.

Muslims pray during Friday prayers at the historic Sultanahmet district of Istanbul, near the Byzantine-era Hagia Sophia, background, Friday, July 24, 2020. (AP Photo/Yasin Akgul)

The move has proven popular with Erdogan’s base, though: dozens gathered outside of the building following the court order last week, and hundreds camped out overnight to be ready for the first prayer on Friday.

Dozens of worshipers broke through one police checkpoint to rush toward Hagia Sophia and social distancing practices, in place due to the coronavirus outbreak, were being ignored, Turkish media reported.

Retired teacher Suleyman Karatas said: “God willing, it will stay as a mosque. Because Hagia Sophia is the legacy of our ancestor.”

CLICK HERE TO GET THE FOX NEWS APP

Erdogan’s government has promised that Hagia Sophia’s artifacts will remain protected, and that the building will still be open to public visits outside of prayer hours.

The Associated Press contributed to this report.