On Sunday, Turkey will hold a national election, less than six months after voters delivered the country's first hung parliament since 2002.

The vote takes place in a climate of real tension and polarization. Months of concerted campaigning by Turkey's main political parties have exacerbated the sense of division within the country. Recep Tayyip Erdogan, who has ruled for 13 years as either prime minister or president, is a man either loved or reviled by his people.

After more than a decade firmly in power, Erdogan's ruling Justice and Development Party, known by the Turkish abbreviation AKP, lost its clear majority in parliament in June elections. The vote was a real blow to Erdogan's aspirations: He had hoped for a super-majority in parliament that would give his party enough of a mandate to rewrite the Turkish constitution and grant the presidency -- a ceremonial and apolitical post that Erdogan has occupied since 2014 -- more executive powers.

Instead, the past few months have seen a worrying unraveling within Turkey, with the economy slumping, the decades-old conflict with Kurdish separatists flaring up, and suspected Islamist militants striking targets within the nation.

Amid this upheaval, opinion polls suggest a similarly inconclusive outcome to the Nov. 1 election. What comes next will have a huge impact not only for Turkey's political future, but a wider region already wracked with instability.

Violence and civil war

On Oct. 10, two bomb blasts ripped through a leftist peace rally in Ankara, the Turkish capital, killing 102 people. It was the worst terror attack in Turkey's modern history. This week, the prosecutor's office in Ankara pinned the blame on Islamic State militants, linking thee explosions to a deadly July bombing of a similar rally in the Turkish border town of Suruc.

But that followed weeks of divisive finger-pointing in the aftermath of the attack. Leftist critics of the government, including members of organizations that participated in the ill-fated gathering, accuse authorities of enabling such terrorism, either through sheer incompetence or tacit support for Islamist forces within the country.

Erdogan, meanwhile, declared that the Ankara bombing was possibly the work of a combined plot of jihadists, Syrian intelligence and the PKK, an outlawed Kurdish militant group that's deemed a terrorist organization by both Turkey and the United States. It's an outlandish theory that holds little water for most analysts, but it reflects Turkey's own political divisions.

The main obstacle to Erdogan's party winning a decisive majority of seats is the Peoples' Democratic Party, or HDP, a left-wing, pro-Kurdish party that surged into parliament in June with the support of a wide spectrum of Turkish secularists, leftists, Kurds and other ethnic minorities. The party's electoral success came at the expense of the AKP, which had earlier relied upon the votes of conservative Kurds.

In recent months, government officials have painted the HDP as a proxy for the PKK -- a charge that carries a certain degree of truth. The HDP emerged from the Kurdish nationalist struggle and some of its members still have relatives "in the mountains," the euphemism often deployed for those in the PKK's ranks.

But the HDP, which espouses peace and a more decentralized Turkish political system, clearly did not want to see the resumption of hostilities between the Turkish state and Kurdish guerrillas in the wake of the June election. According to government figures, more than 150 Turkish security personnel have died in clashes with the PKK; the Turkish military has launched a concerted counter-insurgency campaign, including airstrikes on PKK camps in northern Iraq.

The violence has fanned nationalist flames and spiked anti-Kurdish sentiment in certain parts of Turkey. Erdogan's critics say his rhetoric feeds these tensions.

"[Erdogan's] bitterly divisive rhetoric, which frequently employs religious narrative and the demonization of opponents, has cleaved the country in two: those who love him, and those who hate him," writes columnist Sevgi Akarcesme. "Both parties are equally passionate in their convictions, which makes the divide all the more volatile."

The terror attack in Ankara only exposed the widening rift between these two camps. Some leftist activists reported seeing fireworks being set off in parts of the capital on the day of the bombings.

"The official line is that it's a tragedy," says Nihat Ali Ozcan, an analyst at the Economic Policy Research Foundation of Turkey, an Ankara-based think tank. "But behind the door, people will interpret it according to their own ideological positions."

The Syria question

The Ankara bombing also highlighted the degree to which Turkey is now vulnerable to the ongoing disintegration of the Syrian state next door.

The government has maintained an open border policy with Syria on humanitarian grounds. There are an estimated 2 million Syrian refugees now in Turkey's cities -- a huge burden that has cost the state $8 billion so far in unbudgeted funds.

But it has struggled to deal with flows of foreign fighters into and out of war-torn Syria, and some AKP opponents accuse the government of even abetting certain Islamist factions fighting against the regime of Syrian President Bashar al-Assad.

In the early years of the Syrian war, Erdogan was one of Assad's most outspoken critics, and called on the international community to do more to usher him out of power. His government's foreign policy, which pushed for a more activist role in the Middle East role, appears to have backfired.

Rather than Turkey being able to dictate terms in the Syrian war, the war has come to Turkey in the shape of Islamic State suicide bombings and political instability.

"There is real evidence that the fire in Syria is now spreading to Turkey," said Bulent Aliriza, a Turkey expert at the Center for Strategic and International Studies, a Washington-based think tank.

Turkey is also concerned about the success of Syrian Kurdish militias, whose victories against the Islamic State and their de facto control of a chunk of northern Syria has spurred Kurdish nationalism across the border. The government is also incensed that the U.S. has helped arm and equip Syrian Kurdish factions linked to the PKK, even as U.S. strike craft launch against the Islamic State from Turkey's Incirlik air base.

After spending years calling for a no-fly zone in Syria, Turkish authorities also looked on with dismay as Russia entered the conflict on behalf of the Assad regime.

"The total collapse of Turkey's Syrian policy has been underlined by the fact that both the Russian and American ambassadors in Ankara were formally reprimanded by the government," says Aliriza.

Experts believe the formation of a grand coalition government after the elections would shift Turkish foreign policy back to its more cautious, traditional track. But should the AKP return to power in an alliance with far-right nationalists, there's a likelihood of a real escalation in the Kurdish conflict.

The future of Turkish democracy

Between 2003 and 2014, Erdogan served as Turkey's prime minister and became the country's most significant leader since Mustafa Kemal Ataturk, the founder of the modern Turkish republic.

Under his stewardship, economic reforms led to the emergence of a new middle class. The long-meddling military was brought to heel. And the AKP's brand of religious nationalism, anchored in the Sunni Islam practiced by a majority of Turks, chipped away at a legacy of secularism that had left many Turks feeling marginalized.

But in recent years, the image of Erdogan has shifted from that of a great liberal reformer to a would-be autocrat, bent on consolidating power while pandering to his base.

In the days before the election, Turkish authorities raided the offices of a major media conglomerate linked to the Gulenists, a religious faction now staunchly at odds with Erdogan, and cut the broadcast of one of its news channels. In September, nationalist mobs targeted the offices of Hurriyet, Turkey's leading daily, for its perceived anti-Erdogan coverage.

Samut Karabulut, the deputy chairman of Hakleveri, a leftist organization that participated in the targeted Ankara rally, says the shrinking space for protest contracted even further after the bombing. Major opposition parties declared they would no longer hold large rallies because of the security threat.

"Considering the censorship and the attacks on the press, the only way to oppose was to take to the streets," said Karabulut. "Now they have managed to close that form of dissent as well."

Erdogan and his allies reject the implications of such a claim, and cast themselves as guarantors of stability in the face of myriad forces that endanger the Turkish nation. Many Turks voting on Sunday, no matter for which party, will wonder where that stability has been since the last time they went to the polls.