Turkey’s President Recep Tayyip Erdogan wipes away tears during a ceremony this month in which he rejoined his ruling Justice and Development Party in Ankara. (Press Presidency Press Service via Associated Press, Pool)

Soner Cagaptay is a senior fellow at the Washington Institute for Near East Policy and author of “The New Sultan: Erdogan and the Crisis of Modern Turkey.”

Several recent analyses depict Turkish President Recep Tayyip Erdogan, who is set to meet with President Trump in the White House on Tuesday, as a once moderate and liberal politician who suddenly swerved away toward authoritarianism. I could not disagree more. Erdogan, who has run Turkey since 2002 either as prime minister or president, was always bent on subverting Turkey’s secularist democratic system.

Those commentators who supported Erdogan’s alleged earlier liberalism now find themselves struggling hard to explain his more recent authoritarian turn. They were deluding themselves, and they would have known better had they paid more attention to Erdogan’s biography and mind-set.

To understand Erdogan’s politics, one must first understand his upbringing and early political career in a country then dominated by the secularist ideology of its founder, Mustafa Kemal Ataturk.

As I explain in my book “The New Sultan,” Erdogan was born in 1954 to a poor and socially conservative family in Istanbul’s gritty working-class Kasimpasa neighborhood. His parents migrated to Istanbul from a conservative province deep in the country’s hinterland. Erdogan felt profoundly marginalized growing up poor and pious in the old Turkey, whose leaders banned any role for religion in public life.

During Erdogan’s youth, the staunchly secularist political networks in Turkey, controlled by the country’s small middle classes, treated the poor and religiously conservative as second-class citizens. The publicly funded religious school that Erdogan attended had to face the same sort of institutionalized contempt: Its graduates, though holding high school diplomas, were not allowed to study any university subjects except for theology. In a 2013 TV interview, Erdogan explained how he felt belittled for his education — how other Turks taunted him, for example, by claiming that his schooling disqualified him from any profession other than washing the bodies of the deceased, a task traditionally reserved for the clergy in Islam.

Erdogan confronted similar sentiments after he joined the political Islam movement in the 1970s, which faced constant legal harassment from old Turkey’s political system and the secularist military. Erdogan joined three successive Islamist political parties, each one of which was banned by the Turkish constitutional court in 1971, 1980 and 1998. He was particularly embittered when the democratically elected Islamist Welfare Party, as a member of which he became Istanbul’s mayor in 1994, was ousted by a military-backed “soft coup” in 1997 involving mass rallies by secularists.

Thanks to this background, Erdogan has always wanted to take revenge on the system that repeatedly persecuted the Islamist movement that gave him a political home. Despite his many proclamations of loyalty to democratic principles, Erdogan made his real feelings clear on many occasions. In a 1996 speech, not long before he assumed the office of Istanbul mayor, he declared: “Democracy is a streetcar. It takes you where you need to go, and then you get off.” Since coming to power in 2002, Erdogan has operated according to just such a plan.

First, he built a power base by delivering economic growth, lifting like-minded Turks out of poverty while also molding them into his strongest supporters. Next, moving with his customary caution, he began to undermine the pillars of the secularist system.

His first target was the military. In the course of the 2008 Ergenekon case, which targeted an alleged anti-government conspiracy, then-Prime Minister Erdogan locked up one-quarter of active-duty generals, despite the prosecution’s failure to produce a full and convincing account of the plot. This strategy of intimidation worked. In 2011, bowing to Erdogan’s power, the military’s top brass resigned en masse.

Erdogan moved to create a climate of fear in which he and his Justice and Development Party could openly harass dissidents. The security forces carried out mass surveillance of Erdogan’s secularist opponents, including journalists and university presidents. Officials leaked private phone conversations or email of the government’s critics to the public, while the pro-Erdogan media often linked them to the coup plotters with little or no evidence. Many of those targeted soon found themselves in jail.

Along the way, Erdogan received a helping hand from the liberals and the conservative Gulen movement, both of whom despised the Turkish military and the secularists for reasons of their own. Once he had defeated the first group of foes, however, Erdogan soon turned against his former allies.

His success owes much to his strategy of divide and rule, often persecuting one group while extending olive branches to the others. When Erdogan cracked down on the secularists and the generals, the liberals and the Gulenists helped him. When he moved against the liberals when many of them joined large popular protests in Istanbul in 2013, the Gulenists and the Kurds stood aside. When he went after the Gulenists in 2014, the Kurds looked the other way, and the secularists basked in schadenfreude. When Erdogan finally went after the Kurds in 2015, their potential allies were either on the run themselves or too cowed to speak up.

The abortive 2016 coup attempt against Erdogan, in which Gulenists seem to have played a role, has offered Erdogan a perfect excuse to cement his power through still more mass arrests of his myriad opponents. In this regard, his victory in the recent constitutional referendum is the crowning moment of Erdogan’s authoritarian political trajectory, not its beginning.

Despite his immense power, however, Erdogan still regards himself as an outsider. In many ways, he remains the boy from the wrong side of the tracks, clinging to a lifetime of grievance that expresses itself in a politics of coercion and revenge. This is only exacerbating the intense polarization of Turkish society. Erdogan could halt Turkey’s slide into chaos if he were to overcome the psychological burdens of his past. But this seems a thin thread on which to hang the country’s hopes.