Erdogan, whom critics accuse of cutting an increasingly autocratic figure, faces municipal elections in March that are largely seen as a vote of confidence in his Islamic-based government. A poor result could weaken Erdogan just as he seeks to shift into the presidency in an August vote while still maintaining enough influence in his party to choose his successor as prime minister in parliamentary elections expected next year.
A big setback could end his long pre-eminence over Turkish politics.
Turkey, a largely Muslim nation that straddles Europe and Asia, is a key U.S. and NATO ally with a flourishing economy and stable democracy. Under Erdogan's leadership, the country has increasingly been looking East, cultivating new relations in the Middle East and Asia and casting doubts on its long-standing aim of joining the European Union.
Erdogan's Justice or Development Party, better known by its Turkish acronym AKP, has dominated parliament for the past decade and retains the support of a core religious and conservative base. It could see its majority shrink in elections as unhappy liberals and former allies look elsewhere, although none of the three opposition parties in parliament is likely to overturn that majority.
Erdogan has fallen out with a moderate Islamic movement led by U.S.-based cleric Fethullah Gulen, who is believed to have millions of followers in Turkey and had backed Erdogan's party since it was formed in 2001.
The prime minister, who came to power in 2003, has also lost the support of many liberals, who once saw him as a reformist leader edging Turkey closer to EU membership. His international image also suffered a blow following a violent police crackdown on protests in May and June over government plans to build in a central Istanbul park.
Adding to Erdogan's woes, divisions have even emerged inside the usually tight-knit AKP. Deputy Prime Minister Bulent Arinc, who founded AKP with Erdogan, grumbled on state-run television last month about his treatment by Erdogan and announced he was not running again. Another legislator resigned from the party rather than face ouster for insubordination after he criticized Erdogan on Twitter.
"Erdogan had lost the support of a majority of the liberal circles a long while ago, and now we are seeing political Islam breaking away too," said Cengiz Aktar, a professor of political science with the Istanbul Policy Center. "The local elections will deliver a clear message to the government."
A simmering rift with Gulen's movement came to a head recently after Erdogan's government announced plans to close the private "cram schools" that prepare high school students for Turkey's highly competitive university entrance exam.
Erdogan insists the measure is part of the government's educational reforms. But since about a quarter of the schools are run by the Gulen movement, many see the decision as a way to strip the group of a major source of income and influence.
The AKP-Gulen alliance began to crumble after the movement criticized the government's foreign policy over the past few years, including its deteriorating relations with Israel, as well as Erdogan's uncompromising stance toward the domestic protests.
Analysts say Erdogan has grown weary of the influence of the Gulen movement, whose followers are believed to have a strong foothold within Turkey's judiciary and police. Gulen supporters are thought to have instigated a series of trials against the country's military leaders that helped end the generals' hold on power.
Gulen's movement is a spiritual one and it is not expected to run its own candidates in the elections. However, many of its followers are likely to shift away from the AKP.
"The movement does not tell (followers) who to vote for," said Mustafa Yesil, who heads the Gulen-funded Writers and Journalists' Association. "But we could witness an emotional break (away from the AKP)."
Istanbul will be a major test for the ruling AKP in the March local election. The pro-secular, main opposition Republican People's Party, CHP, appears to have a strong mayoral candidate for Turkey's largest city.
If AKP were to lose Istanbul, it could erode Erdogan's political standing as he faces the presidential election. Internal party rules bar him from a fourth term as prime minister.