Recep Tayyip Erdogan has come a long way in a short time. Just five years ago he was considered a dangerous subversive, sitting out a nine-month jail term for inciting religious hatred. Now he sits on a gilded Ottoman divan beneath a large, formal seascape in the prime minister's official residence in Ankara, the undisputed political master of Turkey. Brussels is so impressed by his European credentials that it's close to opening negotiations to admit his country to one ofthe world's richest clubs of nations.

Erdogan's journey from Islamist firebrand to Euro-friendly premier is remarkable enough. But in the course of it, he and his Justice and Development Party, or AK, have wrought something akin to a modern political miracle. Not so long ago Turkey was a dysfunctional police state and an economic basket case. As recently as 1997 the politically powerful Turkish military removed an elected government from power for being too Islamist. Hundreds of thousands of Kurds were being evicted from their homes in a bloody war against separatists; Human Rights Watch estimated that tens of thousands of detainees were being tortured in police custody. The economy was a mess. Inflation was running at 45 percent just two years ago, and GNP actually shrank. "Turkey had all the classic problems of a Third World country," says one veteran European diplomat. "Joining Europe was an impossible dream."

Then came AK, brought to power in a landslide election in November 2002 that swept away Turkey's old ruling class. Suddenly, everything changed. Over the past 22 months AK has engineered the biggest shake-up of the Turkish state since the days of Kemal Ataturk. Seemingly overnight, the country's generals were cut out of political decision making. Progressive new laws have transformed the social landscape: Turkey's 12 million Kurds have been guaranteed the right to broadcast and learn their own language. The penal code has been rewritten to European standards, abolishing the death penalty, banning torture and excising laws barring criticism of the state. Meanwhile, the economy has gone supernova--growing 13.5 percent in the first half of this year, thanks to banking and finance reforms that drew in foreign investors and cooled inflation to 8 percent.

Erdogan sees all this as much more than the price to be paid for EU membership, or even economic good health. For him, the reforms represent a personal campaign to right injustices he himself suffered. "If I hadn't had the experience of prison, I might have felt differently," he tells NEWSWEEK. "On the question of torture I have said from the beginning, zero tolerance. Why? Because I have seen it and I have lived it. Torture is inhuman. It cannot exist in Turkey."

For this, Erdogan deserves enormous credit. But now he is facing new challenges, played out on a global rather than local stage. It is unclear whether the traits that explain his successes at home will help him realize this future and fulfill his country's enduring dream of joining the European Union. Even though the European Commission's progress report due out this week is expected to recommend starting negotiations, Turkey's EU membership is still far from a done deal. "There is no question that Turkey has a European identity," he says, emphatically. Yet many Europeans are deeply skeptical--and Erdogan himself embodies much of the reason for it.

Exhibit A is the recent flap over adultery. Last month Erdogan almost destroyed his country's EU chances with a misguided attempt to criminalize it. Pressured from Brussels, he reacted with the worst of bad grace, lashing out at his critics: "We are Turks. The EU has no right to interfere in our internal affairs." Never mind that's what Eurocrats do for a living, or that Erdogan soon backed down. Brussels' alarm bells jangled. Was Erdogan really as good a European as they thought he was, or might he be what Turkish secularists have long suspected--a secret Islamist, as parliamentarian Emin Sirin puts it, with "a hidden agenda"?

It's worth delving deeper here, for the adultery affair reveals much about Turkey today and its current leadership. Erdogan and AK rode to power on the long-suppressed frustrations of ordinary Turks, fed up with the incompetence and corruption of their political masters. Erdogan was not of this cronyistic elite. A former footballer who grew up selling sesame buns on the streets of a rough Istanbul slum, he built a reputation (first as a legislator and, later, as mayor of Istanbul) for getting things done by breaking the old-boy rules under which the country was suffocating. Such was the popular hunger for someone like him that he swept to office with an overwhelming parliamentary majority. Yet his success is rich in potentially dangerous ironies. On the one hand, Erdogan has the vision and uncanny domestic political skills to push through dramatic, even revolutionary change. On the other hand, he retains the prejudices and limitations of a rough-hewn man of the people--socially conservative, religious and proudly nationalistic.

It's against this backdrop that the controversy over adultery played out. By all accounts, the idea was solely Erdogan's--not something forced upon him by overly zealous religious leaders. As the prime minister tells it, the law made perfect sense. It was what he viewed as a popular family-values issue, not a religious diktat, and he was genuinely surprised when Europeans took issue with it. "We have no problem over the universal values of the EU or over integration with the EU," he says. "But the EU does not demand that we assimilate completely. This is a moral issue, not a political one."

Europeans obviously did not agree, which raises a question. How could such a knowing and politically deft leader at home be so clueless abroad, particularly at a moment of such consequence for Turkey's future? The answer is more than a little disconcerting. "The problem," writes Atilla Yesilada in a recent report by EuroSource, a New York think tank, "is that Erdogan is not a worldly-wise man." Though superb on the Turkish street, he is something of a rube in Brussels. In outlook and in heart, says Yesilada, Erdogan remains "the inner-city kid from a poor family who received a religious education, cut his teeth in domestic politics and is out of his depth in foreign policy in general and EU matters in particular." This insularity is compounded by the fact that Erdogan often makes his choices based on gut emotion, reinforced by the often provincial attitudes of the AK party leadership. "This is a dangerous mixture," Yesilada concludes, "liable to generate disastrous policy choices in the future."

Already there are worrying signs, beyond the adultery law, suggesting that Erdogan's native Islamist bent, while not fundamentalist, could lead in directions destined to make Europeans anxious. According to EuroSource, AK whips talk openly about introducing more Islamist legislation once Ankara gets its green light on EU accession. In rural areas, reportedly, AK-appointed district superintendents have been demoting female teachers who come to school in trousers. A group of female workers who were denied promotion in the Civil Corps of Engineers recently filed suit in the European Court of Human Rights, claiming wholesale sex discrimination. Meanwhile, in a case which led to headlines in the Milliyet newspaper saying DON'T LET EUROPE HEAR ABOUT THIS! Municipal police in Samsun warned couples against kissing in public on the orders of the local AK Party mayor. Erdogan himself also seems to be gravitating toward leading conservatives in the AK Party. He is supporting Bulent Arinc--an outspoken advocate of the adultery law--for re-election as parliamentary speaker. He is reportedly also thinking of elevating his similarly conservative chief of staff, Omer Celik, to the cabinet. Creeping conservatism will not endear Turkey to a Europe less and less tolerant of any signs of Islamic immoderation.

Turkey's future and Europe's are clearly intertwined, which goes far in explaining the angst clouding their courtship. To judge Turkey just in terms of how it may or may not fit into Europe, though, ultimately misses the real point. The truly remarkable leap forward is the one that Erdogan's reforms--imperfect as they may be--are already effecting within the country. If they continue, Turkey will be the first Muslim country to move from political dysfunction and economic quagmire to being a truly open, law-based civil society. The fact that it stands on equal footing with Europe makes the accomplishment all the more impressive. Other countries in the region will be inspired to follow Turkey's example--proving to skeptical Europeans, and the world, that Islam is not incompatible with democracy. That will be a true revolution.