RECEP Tayyip Erdogan's admirers stretch from the Arab street to the western salon. In the Middle East, the Turkish prime minister is regarded as a courageous champion of the Palestinians. Many western intellectuals also admire Erdogan, believing he has made Turkey a model for an Arab world in turmoil. At home, Erdogan has won three successive elections, presided over an economic boom and enacted important social reforms. Internationally, he has changed a Turkish foreign policy that was overfocused on the west and turned his country into a major player in the wider region. Modern Turkey excites interest and admiration - it seems to show that it is possible to combine Muslim piety with modernity, prosperity and democracy.

The trouble is that all these dazzling achievements risk blinding Erdogan's admirers to their hero's flaws - flaws that are becoming more pronounced as his second decade in power approaches. The Turkish prime minister is becoming more autocratic at home and more reckless overseas. Taken too far, these flaws could endanger Turkey's democracy and its security.

In important respects, Erdogan's record so far has strengthened Turkish democracy. He has expanded minority rights, particularly for the Kurds. Turkey also used to be prone to regular military coups, but that danger has receded. The Erdogan government has arrested generals for their alleged involvement in a coup plot and the military seems now to be sullenly compliant with the country's elected government.

But the backlash against the alleged coup plot has become so widespread that it has swept up many people who are probably innocent of any wrongdoing - but who now languish in jail, awaiting trial or in, some cases, charges. It is not just soldiers who have been arrested. According to the International Press Institute, there are now considerably more journalists in prison in Turkey than in China. There is no doubt, talking to Turkish journalists, that they are now operating in a climate of fear.

The autocratic side of the Erdogan era may become more pronounced. The prime minister has said he will step down after his third term in office. But he seems intent on moving on to the presidency - and on amending Turkey's constitution to endow the presidency with much more extensive powers. If he succeeds, Erdogan would be looking at almost 20 years in power - casting him as Turkey's answer to Russia's Vladimir Putin.

Erdogan's fans in the west are inclined to overlook much of this because they see Turkey as a model for the Islamic world.

One western diplomat says: "Turkey under Erdogan can be very difficult to deal with, but if you told me there was a chance that Egypt would end up looking like Turkey, I'd accept it in a heartbeat."

But Turkey's regional role is not all positive. As he becomes more confident, Erdogan is also becoming more willing to court confrontation. If things go badly wrong, Turkey could find itself facing conflict on three fronts before the end of the year - with Cyprus, with Israel and with the Kurdish PKK insurgency based in Iraq. Erdogan has threatened to use the Turkish fleet to escort "aid flotillas" to break Israel's blockade of Gaza - and to disrupt Cyprus's efforts at gas exploration. Turkish bombers have been pounding PKK bases in Iraq, and a land incursion is a distinct possibility.

Erdogan's recent tour of the Middle East summed up the ambiguity of what he represents. In Cairo, he held up Turkey's secular model as a potential model for Egypt - suggesting that Turkey could indeed show the Middle East how to separate mosque and state. But in a speech in Libya, he played to the most conspiratorial instincts of the Arab street, hailing the Libyan revolution, but suggesting that Britain and France had intervened militarily for commercial reasons. It was a piece of dazzling hypocrisy, given that he had accepted a human-rights prize from Muammar Gaddafi less than a year ago - and initially opposed Nato intervention , in part to protect Turkish commercial interests.

It is still possible that Erdogan will leave a positive legacy. If things work out well, he could be Turkey's equivalent of Luis Inacio Lula da Silva, the much lauded former president of Brazil. The biographies of the two men are strikingly similar. Both emerged from humble origins, served spells in prison and became the political voice of groups that had traditionally been shut out from power. Both men are associated with economic booms and with the emergence of their nations as models for the wider region - and increasingly as global players.

But there are also important differences. Lula pursued a foreign policy that sought always to reassure Brazil's neighbours. After less then a decade in power, the Brazilian leader stepped aside. Like Nelson Mandela, Lula knew when to go. Unfortunately, there is little indication that Recep Tayyip Erdogan has the same self-restraint or humility. ©2011 The Financial Times Limited