To understand Erdogan's dilemma, it helps to understand the depths of Turkey's commitment to secularism. It began with the very establishment of the Turkish Republic in 1923, and the founding father Mustafa Kemal Ataturk's rejection of traditional Islam as incompatible with his goal of establishing a modern European state. Ataturk shut the Islamic caliphate, dissolved religious courts, outlawed mystic sects and secularized schools. He replaced the Arabic script with Latin script. He outlawed the fez and all but imposed the homburg. He adopted the Swiss civil code and granted women the vote.

As secular nationalism became Turkey's religion, the military took on the role of protecting Ataturk's legacy, which meant keeping elected officials on a leash and overthrowing or undermining them if necessary. Erdogan himself is unofficially on probation. Turkey's ''deep state'' sees its duty as preventing the nation from backsliding into religion and ethnic, especially Kurdish, separatism. Islam was, of course, never snuffed out. While most Turks came to consider themselves Turks first, they were still Muslims. And from the start, especially in the heartland, traditional Islam survived despite repression. To this day, in what seems an arcane, self-defeating expression of Turkey's secularism, women wearing head scarves are not allowed to attend universities or work in government. Prime Minister Erdogan's two daughters, in fact, go to Indiana University, where they are free to cover their hair and get a degree at the same time. His wife does not appear at state functions lest her designer head scarf provoke fears of an imminent theocracy.

Erdogan's family comes from a devout world in the Black Sea region. His father, Ahmet, migrated to Istanbul in the 1930's, settled in Kasimpasa, a rough working-class quarter, and found work as a captain with a state maritime company. Kasimpasa has a body language all its own, and Turks say that Erdogan retains the Kasimpasa swagger, a way of leading with his right shoulder. Although the district was infamous for its gangs and pickpockets, Erdogan remembers the neighborhood as an idyll, with fruit trees and fields, where kids could get their hands dirty. ''I was shaped by that mud,'' he said, ''not like the poor kids of today who are surrounded by asphalt.''

Near the now-ramshackle mosque where Erdogan studied the Koran as a child, the district manager of Kasimpasa, Ali Riza Sivritepe, spoke of growing up with him. They fetched water from the same well, flew kites and shot marbles over the irregular paving stones. (Erdogan, steely in his ambition even then, always won.) ''He was a very serious child,'' Sivritepe said. ''Everyone respected him here and called him Big Brother.''

His father, according to a biography, was an authoritarian with a temper that could be tamed best by Erdogan's kissing his shoes. Once, Erdogan's father punished him for using bad language by hanging him from the ceiling by the arms. ''After that day, I never swore again,'' Erdogan said.

When Erdogan was 7, Prime Minister Adnan Menderes -- ''God bless his soul,'' Erdogan said -- was hanged. Elected in 1950 in Turkey's first free elections, Menderes was a secularist but demonstrated a tolerance for religious practice that his predecessors had not possessed. Over 10 years in government, he faltered and became repressive, and when the Turkish military overthrew him, the coup was largely welcomed. But when Menderes was sent to the gallows, many Turks were horrified. ''Some are saddened by things like this, and they give up,'' Erdogan said. ''In my case, this sadness turned into an attraction for politics.''

Part of the Erdogan lore is that in fifth grade he refused to use a newspaper as a prayer rug in a religion class. It was inappropriate, he told his teacher, who took a special interest in him and persuaded Erdogan's father to send him to a state-run Prayer Leaders and Preachers school, which offered a secular curriculum amplified by religious instruction. Erdogan was particularly good at reciting nationalist poetry. During poetry contests, Sivritepe recalled, Erdogan would hide a Turkish flag inside his shirt and whip it out for dramatic effect.