The surprising margin of victory for President Recep Tayyip Erdogan's party in parliamentary elections marks a remarkable turnaround and puts him firmly in control of Turkish politics.

Among the challenges Erdogan will have to navigate are renewed threats of civil war in the Kurdish southeast as well as a wave of Syrian refugees pouring across Turkey to Europe and major instability across its borders as the Islamic State group wages battle in Iraq and Syria.

The Justice and Development Party, or AKP, came roaring back just five months after losing its majority in a June parliamentary election, nearly doubling its closest rival in support and improving its results by millions of votes and about nine percentage points. The party has already been in power for more than 13 years, and the win cements it position until 2019.

The election was effectively a referendum on Erdogan's leadership though he was not on the ballot. Erdogan took a huge gamble by ordering new elections after fruitless coalition talks following the June election. Had his party faltered, it would have had to invite a rival into a coalition, checking Erdogan's dominance.

Between the two elections, Erdogan consolidated his grip over the party by having loyalists appointed to its leadership and candidate lists. But he is still in the awkward position of ruling as president because the post has limited constitutional powers in Turkey. For now, he is forced to rely on Prime Minister Ahmet Davutoglu to wield the levers of power in his favor. He is expected to push for constitutional change to grant the presidency sweeping new powers, but the election left him short of the supermajority required to do that without help from the opposition.

Since June, Turkey has seen the outbreak of its worst violence in years. A once promising peace process with the Kurdistan Workers' Party, or PKK, has gone off the rails and two massive suicide bombings at recent pro-Kurdish gatherings killed some 130 people. Evidence that they were carried out by the IS group suggests that chaos from the war in neighboring Syria has spilled into Turkey.

Earlier claims by the Turkish government that authorities had a handle on the militants on both sides of their border appear to be a miscalculation.

The election itself was polarizing and leaves serious fissures in Turkey. During peace talks over recent years, Erdogan cultivated ties with Kurds and made a partner of the leftist pro-Kurdish People's Democratic Party, or HDP, in the discussions. The two parties, despite coming from opposite ends of the political spectrum, flirted with a deal that would expand rights and autonomy for Kurds in exchange for agreeing to strengthen the president's powers.

But talk of such a deal fell apart when the HDP cleared a 10 percent threshold for entering parliament for the first time in the June elections, depriving Erdogan's Justice and Development Party of its ruling majority — and then declared it would not support new presidential powers.

In the second campaign, Erdogan castigated HDP as the political arm of the PKK, which Turkey and most Western countries consider a terrorist organization. Fighting between the PKK and government forces left hundreds dead. But Erdogan campaigned on a promise to restore security and stability and has emerged in a stronger position to return to the peace process if he chooses.

So far he has given few clues about moving in that direction, although Davutoglu signaled in his post-election comments that the party had not abandoned hopes for peace.

Meanwhile, there are tensions building with the United States because a key partner in Syria for the U.S.-led fight against the Islamic State group is an affiliate of the PKK. The U.S.-backed Kurdish rebels in Syria have made major advances in recent months along Turkey's border, and Erdogan has vowed to intervene if they take territory across the Euphrates river. If Turkey were to beat back such a PKK advance, it could effectively amount to defending IS.

As the chaos in Syria widens, however, Erdogan appears to be strengthened in talks with the European Union on stemming the flow of refugees to Europe. More than 2 million Syrians have taken refuge in Turkey and many of them want to go to Europe. The two sides have been discussing a deal to offer aid and concessions to Turkey in exchange for measures to halt the flow. Erdogan can now negotiate without regard to an opposition party.

One factor that may be out of Erdogan's control is the economy. On Monday, the Turkish lira and stock market soared as investors calculated that single-party rule will be good for business. But Turkey faces bumps ahead amid the likelihood of rising interest rates in the U.S. that will suck money out of emerging markets. Analysts say that Turkey faces fundamental problems, including a current account deficit, and doubts that Erdogan is a good steward of the economy.

All of these challenges could overwhelm Erdogan's capacity to deliver on a promise of stability.

___

Desmond Butler is the chief correspondent in Turkey for The Associated Press.

___

Follow Butler at https://twitter.com/desmondbutler