Supporters of President Recep Tayyip Erdogan hang an effigy of U.S.-based cleric Fethullah Gulen during a pro-government demonstration last month in Taksim Square in Istanbul. (Kursat Bayhan/Getty Images)

Last month’s failed coup brought into relief a bitter struggle at the heart of Turkish politics.

From his humble childhood in a working-class neighborhood of Istanbul, President Recep Tayyip Erdogan has steadily transformed the nation in his image over almost a decade and a half in power and become the Turkish republic’s most influential leader since its founder, Mustafa Kemal Ataturk.

Halfway around the world, Fethullah Gulen, a 77-year-old imam, presides over a somewhat opaque network of schools, charities and businesses in Turkey and more than 100 other countries. He has lived in self-imposed exile in the United States since 1997 and has acted as a kind of global spiritual leader, advocating peace and tolerance.

Just years ago, the two devout rivals were locked in a tactical alliance against an old enemy — Turkey’s once-entrenched secularist establishment. But the understanding between their camps eventually crumbled into a fight for power, one that came dramatically to the surface in the July 15 coup attempt by a rebellious faction of the military. Some 270 people died during the 12-hour revolt, including 24 of the coup plotters.

Now an enormous purge of suspected Gulenists is underway.

Turkish Muslim cleric Fethullah Gulen sits at his residence in Saylorsburg, Pa., in March 2014. (Selahattin Sevi/AP)

[An old-school coup fails to topple Turkey’s powerful president]

Much of the Turkish public and the main opposition parties have rallied around the government despite their differences. Gulen and his congregation seem to be everyone’s scapegoat.

Not long ago, though, Turkey’s leadership had a very different perspective.

In May 2012, Turkey’s then finance minister delivered an hour-long address to the Rumi Forum, a Washington-based interfaith organization that espouses Gulen’s teachings. The minister, Mehmet Simsek, chatted about his country’s economy. The tone of the conversation was that of a dialogue among friends.

Simsek, now a deputy prime minister who voiced angry attacks on Gulen after the failed coup, is hardly alone. An array of officials from Erdogan’s ruling Justice and Development Party, or AKP, who once collaborated with Gulenists have vociferously condemned the preacher’s movement.

The Gulenists chose to strike last month, Ankara’s narrative goes, once they became aware of government plans to oust them from positions in the military. Senior AKP politicians have likened Gulen to Osama bin Laden and Iran’s Ayatollah Ruhollah Khomeini, a cleric in exile who returned home at the right moment to found a theocratic republic.

Gulen and his supporters overseas strenuously deny involvement in the coup plot and reject such characterization. His sympathizers invoke the not-so-distant past.

“Why did Erdogan support the movement more than a few years ago,” asked Sevgi Akarcesme, the editor of a now-shuttered newspaper connected to Gulen’s movement. “Why did they openly support Gulen events?”

Since 2013, the rivalry between the AKP and the Gulenists has shadowed Turkish politics. The government carried out small-scale purges and actions against perceived Gulenist organizations, including the Zaman newspaper, which was once Turkey’s biggest daily and Akarcesme’s employer until the state seized it in March.

AKP leaders now say they were hoodwinked by their old alliances.

“For a long time, we couldn’t see that this group was an instrument and cover for other goals and sinister calculations,” Erdogan said in a speech on Wednesday.

[The execution of a former Turkish leader that still haunts Erdogan]

Gulen has repeatedly denied any direct connection to the coup plot.

“If there is anything I told anyone about this verbally, if there is any phone conversation, if one-tenth of this accusation is correct . . . I would bend my neck and would say, ‘They are telling the truth. Let them take me away. Let them hang me,’ ” Gulen said in an interview with CNN Sunday.

The Turks have requested Gulen’s extradition from the United States. American officials said they have yet to see sufficient evidence implicating him.

The new-age preacher

When the AKP came to power in 2002, it was a party largely composed of political outsiders, at odds with the military as well as a secularist establishment that had long balked at Islam in politics.

“The AKP had nothing except for its popular support. It came into government as if it was like an alien from Jupiter or Saturn landing on Earth,” said Halil Berktay, a professor of history at Sabanci University in Istanbul, adding that Erdogan’s party eventually “concluded an unholy alliance with the Gulenists” already installed in various corners of the Turkish state and enabled the promotion of countless more over the years.

The AKP and the Gulenists “have the same ideology. They both want to see a religious country, to give it the color of Islam,” said Levent Gultekin, a former Islamist and a popular commentator and columnist. “It’s just their direction is different.”

While the AKP’s ticket was mass mobilization and electoral democracy, emerging as the party of pious conservatives and merchant classes outside the country’s cosmopolitan coastal cities, the Gulenists entered the state in a more clandestine fashion.

The preacher’s movement espouses a kind of moderate Islam and a rhetoric of modernity, peace and service, which its adherents say should be seen as an antidote to the extremism of groups such as the Islamic State.

But if you listen to the Gulenists’ critics, the group operates with the cultish weirdness of Scientologists and militant discipline of the Jesuits.

The cemaat, or congregation, as most Turks refer to the movement, came to the fore in the 1980s after a military coup that targeted leftists and created space for a kind of political Islam to make inroads in doggedly secular Turkey. Its supporters set up schools that churned out a new generation of civil servants and intellectuals who started to enter the ranks of the government bureaucracy once wholly dominated by Turkey’s secularist elite.

A network of Gulen-linked business groups, charities and schools spread around the world and, in some places, served as a surrogate for Turkish soft power — it is said, for example, that the aggressive Turkish diplomatic expansion in Latin America and Africa under Erdogan’s watch was facilitated by Gulenist contacts. Two leading schools as well as a hospital connected to Gulen in Mogadishu, the war-ravaged capital of Somalia, were shut down in the days after the failed coup.

In Western capitals such as Brussels and Washington, Gulenist-led organizations often acted as an informal lobby group for Ankara.

But at home, the secretiveness of the organization — even experts on the Gulenists are not certain how large the cemaat’s membership is — surrounded it for years in a thick cloud of suspicion and fear.

A power struggle

Beginning in 2007, pro-Gulen prosecutors launched a string of investigations into the military for alleged plots to overthrow Erdogan’s government. Hundreds of military officers were eventually sent to jail.

But as legal proceedings dragged on and arrests mounted, the trials began to look more like a Pyrrhic victory for Erdogan, who was eventually forced to distance himself from the hearings as they seemed to turn into a witch hunt.

Some of the cases involving Gulen-linked prosecutors had used falsified evidence, and higher courts eventually overturned the convictions in both cases.

Ilker Basbug, a former chief of the Turkish military and one of the generals who was convicted and later exonerated, told CNN Turk this week that he had warned the AKP about the threat posed by the Gulenists.

“I said to them today the threat is to us,” Basbug said, referring to the military, “but tomorrow it will be you.”

By December 2013, the alliance had totally fallen apart, with the Gulenists installed in Turkey’s police and judiciary launching corruption probes into Erdogan and his government that led to four ministers losing their jobs. The investigations faltered as the AKP hit back.

It’s not quite clear who cast the first blow. Observers suggest it also had to do with growing tensions over the control of Turkey’s intelligence agency and Erdogan’s increasing annoyance with the extent of Gulenist infiltration.

Authorities started closing Gulen-linked schools and media outlets, while commencing a steady purge of the police and judiciary. By the end of 2015, the AKP government had declared Gulen’s movement a “terrorist organization.”

According to government statements after the failed July 15 coup attempt, intelligence officials had known for about a year of some 40,000 suspected Gulenists in the country, including 600 senior military officers, after decrypting millions of text messages sent through a messaging app.

Now, Turkey is in the grips of an unprecedented crackdown. The government declared a three-month state of emergency, and some 80,000 people have been detained, arrested or suspended from their jobs.

[Turkish authorities expand massive purge of opponents]

International rights groups and opponents of the government are deeply concerned by the scale of the backlash, which has netted numerous liberal journalists and others with little real connection to Gulen, they say.

“There are signals of the intention to fabricate thought crime and collectively punish people,” said Sezgin Tanrikulu, an opposition parliamentarian.

Yet, by and large, there is little sympathy for the Gulenists among the wider Turkish public, even among those who are opposed to Erdogan’s increasingly authoritarian style. Opinion polls indicated vast majorities pinning the coup on the cleric and his followers.

“People realize, at the end of the day, they can get rid of Erdogan at the voting booth,” said Gultekin, the columnist. “But how do you get rid of Gulen?”

Erin Cunningham and Zeynep Karatas contributed to this report.

Read more:

Turkish lawyer files complaint accusing U.S. generals of aiding coup attempt

Turkey’s Erdogan always feared a coup. He was proved right.

Today’s coverage from Post correspondents around the world