Cairo - When Pope Francis visits Egypt's Al-Azhar this week, he will find support for his message of peace in the venerable Islamic authority praised as a bulwark against extremism.
But his visit comes as Al-Azhar, which runs one of the world's oldest universities, is under fire from critics within Egypt who say the Sunni Muslim institution has itself become part of the problem.
Al-Azhar had been at the centre of a messy collision between politics and theology since President Abdel Fattah al-Sisi began campaigning for religious reforms, with profound implications for Islamic doctrine.
A former army chief who overthrew his Islamist predecessor in 2013, Sisi believes that Islamist extremists have not been properly challenged on theological grounds.
"He thinks that extremist ideas have thoroughly infiltrated Muslim societies and they are latent" but could set off "a tidal wave of devastation," said a member of a foreign delegation that met Sisi.
Al-Azhar and its Grand Imam Ahmed al-Tayeb have warily endorsed Sisi's call for reforms.
Dating back almost 1 000 years, the prestigious institution runs a university and schools across the country, and thousands of international students from as far as China come to study religion and return home as clerics.
The clergy of the traditional Sunni bastion loathes the theology of jihadists inspired by the puritan Salafism dominant in Saudi Arabia.
Privately, however, many of Al-Azhar's clergy and professors resent the former army officer's attempt to reshape Islamic thought.
The manner in which he pushed for the reforms further scandalised some clerics, especially when he suggested that he would complain about them to God if his call went unheeded.
"By God, I will contest you before God on the Day of Judgement," Sisi told the clerics in a 2015 speech outlining the need for religious reforms.
"The religious establishment - not all of it but most of it - is pretty resistant to the idea of somebody from outside interfering or stipulating how religion and religious discourse should function," said H.A. Hellyer, a non-resident senior fellow with the Atlantic Council.
In a meeting with another foreign delegation, "Tayeb openly scoffed at the idea for religious reform that Sisi has promoted," a delegation member told AFP, saying "the problem is unemployment and inequality."
Members of both delegations requested anonymity because they were discussing comments made in private.
Sisi's calls for reforms emboldened secular and modernist critics of Al-Azhar as well as clerics seeking influence with the president.
One such cleric, endowments minister Mokhtar Gomaa who runs the country's mosques, decided to impose a written Friday prayer sermon on all preachers to weed out extremist rhetoric, which Sisi had demanded.
Al-Azhar mutinied, forcing Gomaa to back down, and Sisi distanced himself from the attempt.
"Whenever I see the Imam, I say your excellency the Imam, you're torturing me," Sisi said in a speech attended by Tayeb after the controversy.
"He says to me: 'Do you love me or what?' I say: 'Your excellency the Imam, I love you.'"
Secular and reformist critics of Al-Azhar also felt encouraged by Sisi. One, Islam el-Behairy, went so far as to attack canonical Sunni books as inspirations for extremism.
Behairy and other critics pointed to classical manuals of Islamic jurisprudence taught at Al-Azhar that contained antiquated rulings on slavery, women and non-Muslims that may be jarring to a modern reader.
The institution's professors say their students understand that those texts were written in a different age and not all their content applies in a modern context.
After an uproar by Al-Azhar, Behairy ended up serving a prison sentence for "insulting religion".
"Many of my colleagues and students feel we are under attack, starting with Behairy," said one professor at Al-Azhar, referring to criticism of the institution.
The tensions mounted when Sisi demanded in January that the clerics look into amending divorce procedures to invalidate the Islamic practice of verbal divorces.
Al-Azhar's top body, the Council of Senior Scholars, flatly refused. "It was a consensus vote," a cleric who sits on the council told AFP.
Following three Islamic State group suicide bombings of churches that killed dozens of Coptic Christians in December and April, the pressure doubled on Al-Azhar.
Critics lambasted Al-Azhar and Tayeb in talk shows and newspapers for failing to counter the extremists and not reforming its university and high school curriculums.
Mohamed Abu Hamed, a lawmaker, introduced a bill to reform the institution, which the constitution empowers as Egypt's authority on "Islamic affairs."
The bill includes term limits for the Grand Imam, who currently can serve as long as he wants.
"We found that the curriculum of Al-Azhar and its institutions contains many ideas that lead to violence or even incite violence," Abu Hamed told AFP.
Al-Azhar rejects the accusations, pointing out the conferences it has organised to counter extremism and a monitoring group it set up to challenge their ideology.
"The criminals who commit these crimes do not include a single suicide bomber who studied even for a single day in Al-Azhar," Tayeb's deputy Abbas Shoman said in a newspaper interview.