Turkish President Recep Tayyip Erdogan has been consolidating his influence for decades on the back of his personal popularity.

President Erdogan captured the nationalist spirit with his tough policies against the Kurd separatists and what he characterizes as anti-Turkish parties. His snap September election delivered 50 percent of the ballots to his Justice and Development Party (AKP). He told the crowds that a vote for the pro-Kurdish People’s Democratic Party was a vote against Turkey.

Now that he was riding the wave again his aim was to change the constitution to allow for powers currently residing with the prime minister to be transferred to the presidency. This is a hot button issue in the country and it appears that former Prime Minister Ahmet Davutoglu wasn’t convinced, so was prodded to step down to make way for the more amenable Binali Yildirim, one of Erdogan’s former advisers and loyal supporters.

However, since then the country’s economy has been shaken due to the repercussions of Turkey’s deliberate downing of a Russian warplane on the border with Syria, which led to a major rift affecting trade, tourism and the real estate sector. The situation has been worsened by a series of terrorist attacks, three this year alone, and clearly Erdogan was galvanized to mend fences with both Russia and Israel despite his earlier assertions that re-establishing full diplomatic relations with Israel was conditional upon an end to the siege of Gaza.

The president has been aware for a very long time that he has enemies in country and has purged the military, the judiciary, the police and the media of opposing voices, including those with suspected sympathies with his one- time friend-turned-nemesis Fethullah Gülen, a theologian who heads the Gülen Movement and now lives in reclusive self-imposed exile in Pennsylvania.

The movement is believed to have millions of adherents in the United States, Europe, Africa and Asia and owns media outlets, businesses and schools. When a corruption scandal broke in 2013 involving several within the Turkish government, it was dismissed as a Gülenist plot by President Erdogan who promptly dismissed, demoted or imprisoned all those involved with pursuing it further.

Within hours of the news that an attempted coup was underway last Thursday, the president announced that Gülen was the orchestrator.

“I have a message for Pennsylvania. You have engaged in enough treason against this nation. If you dare, come back to your country.”

Erdogan has apparently requested his extradition from the US, which will be considered as long as Turkey goes through the proper channels and can present hard evidence that a crime has been committed.

The Obama administration is in a tight spot. It will have to be seen as following legal procedures with regards to any extradition but it cannot afford to alienate the Turkish president when the country is a NATO member, works in partnership with the US to eviscerate Daesh and, most importantly, permits the US Air Force to conduct sorties into Syria and elsewhere from the Incirlik Air Base.

Erdogan says the military will be subjected to a further purge and in the meantime, the government has authorized mass arrests of generals, high-ranking officers and soldiers; 2,839 in total. Some 2,745 judges have been sacked. Erdogan has pledged to “exact the highest price” from the perpetrators.

According to the Turkish paper Hurriyet, many of the junior soldiers detained revealed under questioning that they had no idea they were taking part in a coup until furious civilians confronted their tanks. They were under the misconception a military drill was underway. Some were beaten by the crowds of Erdogan supporters or were taken into custody by the police.

President Erdogan’s popularity has once again soared. Democracy has been preserved and the Turkish leader has proved to be invincible against both opposition parties and disgruntled military chiefs. The coup attempt has handed him every justification to weed out “traitors” wherever they may be and to expand presidential powers.