They came by the thousands, pouring through the ancient stone archways and into the gleaming white marble courtyard of al-Azhar mosque. The faithful had come to pray, to hear a thundering sermon from a leader of Hamas and to witness a rebirth.

Co-opted for decades by irreligious and autocratic Egyptian governments, al-Azhar was retaking its rightful place as the world’s leading voice of Sunni Islam, worshipers said. The presence of a once-banned Hamas preacher willing to speak incendiary truths was proof that the millennium-old mosque and university that bear the al-Azhar name had finally been set free.

“Before, al-Azhar was covered by dust,” said Yasser Abdel Monen, 32, beaming in the shadow of the building’s towering minarets. “Now we have removed the dust to show what it is truly made of.”

But to others, that Friday sermon late last month was proof of something more ominous: the perverse outcome of a revolution built on a thirst for freedom but overtaken by a hunger for hard-line religious dogma.

More than a year after an uprising that deposed longtime president Hosni Mubarak, just about everything in Egypt feels up for grabs. Yet the struggle for the soul of al-Azhar carries a special resonance here and across the Islamic world. At a time when the Middle East boils with debate over the proper role of religion in public life, al-Azhar is poised to wield vast influence over how political Islam is implemented regionwide.

Now, forces from across Egypt’s political and religious spectrum — including a group preaching a puritanical, Saudi-style doctrine of Islam — are maneuvering to influence al-Azhar.

Since its founding in the 10th century, al-Azhar has been an unrivaled touchstone of Islamic thinking, guiding the devout in their understanding of the faith and educating millions through its distinguished university and education system. In modern times, it has been a moderate bulwark against more extreme interpretations of Islam, condemning terrorist attacks, sanctioning broader rights for women and building bonds with Egypt’s Christian minority.

But in recent decades, al-Azhar has also been sullied by its affiliation with a string of Egyptian leaders who used the institution’s good name to give their policies a religious blessing. Since 1961, al-Azhar’s top official — the grand sheik — has been appointed directly by Egypt’s president. For many Egyptians, al-Azhar became just one more tool of state control.

In the aftermath of the revolution, there is widespread agreement among politicians in Egypt that al-Azhar needs greater independence. The question is whether that also means a lurch toward a more rigid and less tolerant school of Islam to match the increasingly doctrinaire mood of the Egyptian people.

There is evidence that such a shift is underway and that it could go much further.

Members of Egypt’s two main Islamist groups — the Muslim Brotherhood and the Salafist Nour party — control between them an overwhelming majority in Egypt’s new parliament. Seated in January, they are already working on legislation that would strip the grand sheik of his lifetime appointment and that could give them a major say in picking a successor.

The current grand sheik, Ahmed el-Tayib, is a Sorbonne-educated scholar who emphasizes interfaith dialogue and is known for his relatively progressive fatwas, the religious pronouncements that carry the weight of law when issued by al-Azhar. But he was also a committee member in Mubarak’s hated National Democratic Party and was appointed by Mubarak himself.

Just days before the new parliament was sworn in, Egypt’s ruling generals approved a law that would authorize a committee of scholars to choose the grand sheik but that would effectively allow Tayib to pick the committee.

Politicians from Nour and the Brotherhood, who have been reluctant to challenge the nation’s military rulers on many issues, say they will fight on this one. They argue that Tayib is too closely tied to the old regime to lead an organization that will pass judgment on the religious merits of everything Egypt’s new government tries to do.

“Liberating state institutions like al-Azhar is even more critical to us than the presidential election or rewriting the constitution,” said Mohammed Nour, the Nour party’s spokesman. “Ensuring the independence of the institution that determines what is and is not Islamic is extremely important.”

Nour said the only way to guarantee genuine independence is to open up the grand sheik position to an election — one in which all al-Azhar University graduates get to vote, or even all Egyptians.

“If we’re talking about instilling democratic values in our society, then why should the position not be open for everyone to vote?” said Nour, who has a thick, bushy beard and an office overlooking the Nile.

Quiet confidence

Behind the appeal to democratic values lies a quiet confidence: Nour’s brand of Islam, the austere and puritanical Salafi school, has rapidly gained adherents in Egypt in recent years.

A close cousin of the Wahabi branch of Islam that is favored in Saudi Arabia, Salafi thinking is beamed into Egyptian homes via satellite television programs featuring Persian Gulf-based preachers. Saudi money, meanwhile, funds the operation of Salafi mosques across Egypt.

As the Salafi approach has surged in popularity, al-Azhar’s moderate teachings have waned because of the taint of association with repressive governments.

The two schools are very different. Al-Azhar teachings have traditionally focused on religious pluralism and have adapted ancient dictates to the realities of a modern world. Salafis prefer rigid tests of faith, such as the length of a man’s beard, and counsel a literal interpretation of Islam’s holiest book, the Koran. The differences help explain why in Saudi Arabia women are not allowed to drive a car but in Egypt they can initiate a divorce.

In the grand sheik’s modern office complex in downtown Cairo, advisers acknowledge that their way of thinking is under threat.

“Undoubtedly, al-Azhar is being targeted,” said Mohammed Mehana, a dapper university law professor who counsels the grand sheik. The challenge, he said, comes from “new religious currents that are popular on the street but are scholarly inaccurate and are dissimilar to the moderate school of thought at al-Azhar.”

Rather than fight the challengers head-on, the grand sheik has tried to appease them, analysts say.

“In the final analysis, they are in competition. But for now, they’re collaborating,” said Ashraf el-Sherif, who teaches political science at the American University of Cairo. “The Salafists want to gain the scholarly credibility of al-Azhar. Al-Azhar wants to win the street popularity of the Salafists.”

The Muslim Brotherhood, which is the dominant force in the new parliament and is considered more moderate than the Nour party, is also making inroads at al-Azhar, an effort that Sherif said will be critical to advancing the group’s political agenda.

“They want leverage over the foremost religious institution in the country so that their understanding of religion becomes the centrist understanding of religion,” Sherif said.

The Brotherhood’s newfound influence was on full display Feb. 24, when Ismail Haniyeh, the prime minister in Hamas-run Gaza, spoke at al-Azhar after Friday prayers. Just over a year ago, Haniyeh’s presence would have been unthinkable. Hamas, the militant Palestinian group, and the Brotherhood are part of the same Islamic movement, and both were banned under Mubarak, whose government upheld a peace treaty with Israel.

But on that day, al-Azhar gave Haniyeh a rapturous welcome. As he proclaimed from the pulpit that Hamas would “liberate” Jerusalem, home to the revered al-Aqsa mosque, the Brotherhood-dominated crowd of worshipers chanted back, “From al-Azhar to al-Aqsa we will march, millions of martyrs.”

Student union elections

On al-Azhar University’s main campus — a palm-tree-fringed idyll amid Cairo’s frenetic urban sprawl — students say the Brotherhood and the Nour party are both ascendant.

Before the revolution, students affiliated with either political movement were routinely kicked out of campus housing and occasionally hauled away for interrogation at the hulking concrete state security complex directly across the street from campus.

“I was constantly being referred to the disciplinary committee because I was engaging in unauthorized political activity,” said Abdel Rahman, a soft-spoken and mild-mannered fifth-year medical student.

But in April, Rahman and his fellow Muslim Brotherhood leaders swept to victory in student union elections — an outcome that would presage the national parliamentary vote later in the year.

Rahman said that the Brotherhood’s ideology is already aligned with al-Azhar’s — the group’s founder was an al-Azhar graduate — and that the movement does not plan a takeover.

“Any clash or confrontation isn’t an option,” he said. “Al-Azhar has been here for 1,000 years, and the Brotherhood has been around for 80. We consider ourselves the sons of al-Azhar.”

That is not to say the campus is free of discord. In January, a group of left-leaning students organized the screening of a film focused on abuses by Egyptian security forces. But Salafi students, who are an increasingly visible presence on campus, showed up and smashed the projector, according to Wesam Ata, 20, one of the organizers.

“Their attitude is, ‘If you disagree with me, you are my enemy. And I speak the word of God, so you are an enemy of God,’ ” said Ata, who studies at al-Azhar’s business school.

It is that attitude that has so unnerved Egypt’s liberals and religious minorities, who fear that any move toward Salafi thinking at al-Azhar could be destabilizing at a time when the country is already on edge.

Mona Makram-Ebeid, a leader of Egypt’s Coptic Christian minority, said al-Azhar’s grand sheik has done more than anyone to bring the country together after the revolution.

“Any shift to Salafism would be catastrophic, both for al-Azhar and for society,” she said.

Ibrahim el-Houdaiby, a young activist and scholar who has studied under an al-Azhar sheik, agrees. But he does not think it will happen.

Houdaiby’s mentor, Sheik Emad Effat, was shot dead by security forces in December during a protest against military rule. Like Effat, Houdaiby said he believes that al-Azhar needs to return to its roots as an independent and respected source of Islamic scholarship. Once it does, he said, more extreme ideologies will lose the appeal they have gained in recent decades, when al-Azhar’s moderate voice was discredited by its ties to corrupt Egyptian governments.

“Al-Azhar is an institution capable of regaining its authenticity, regaining its intellectual soundness. If people want a genuine exchange of ideas, then an authentic al-Azhar is a place to look,” Houdaiby said. “And if people want to know what went wrong in this region, then al-Azhar’s history is a place to look.”

Special correspondents Lara El Gibaly and Haitham El Tabei contributed to this report.