Turkey on Sunday appeared set to narrowly approve a new constitution that will give President Recep Tayyip Erdogan sweeping new powers and allow him to rule for more than a decade to come.

While Erdogan and the ruling AK Party waged a fervent, months-long campaign to push a “yes” result, Sunday’s vote did not yield a decisive victory but instead highlighted stark divisions in the country.

With nearly all ballots opened, Erdogan’s supporters took home 51.3 percent of the vote, according to the state-run Anadolu news agency. But members of the opposition on Sunday night demanded a recount, blasting a last-minute decision by the electoral commission to accept unstamped ballots as valid votes.

The changes to the constitution will have wide-ranging effects, such as increasing the number of seats in Parliament, but the greatest change is the powers granted to the president. Erdogan will be head of the executive and of the state, doing away with the role of prime minister. He can dismiss Parliament, call a state of emergency, appoint ministers and judges ― all without approval from lawmakers.

The constitutional changes also include a provision that the president will be eligible to hold office for two five-year terms. Turkey has elections scheduled in two years, which means that Erdogan could be in power until 2029.

Umit Bektas / Reuters Turkish President Tayyip Erdogan addresses his supporters in Izmir, Turkey, during a rally for the upcoming referendum on April 9.

Turkey has been mired in turmoil since an attempted coup last year failed to topple Erdogan, and the government continues to crack down on perceived dissent in public and private institutions in its aftermath. There is also a resurgent conflict between Kurdistan Worker’s Party (PKK) militants and the government, which has led to rebel bombings and harsh reprisals from authorities.

Erdogan argued that an executive presidency through a new constitution will provide the reform that Turkey’s often gridlocked political system needs, as well as bring about more stability. Throughout the campaign, Erdogan also tried to drum up nationalist support by pushing a narrative that Turkey is taking a stand against other nations seeking to vilify it ― a tactic that included him accusing Dutch and German governments of Nazism during a diplomatic spat last month.

The political situation in Turkey has changed significantly since the 2016 coup attempt, which Erdogan blames on exiled U.S.-based cleric Fethullah Gulen. In an attempt to remove dissent, Turkish authorities have fired or imprisoned tens of thousands of people, including academics, journalists and members of the armed forces. At least 40,000 teachers alone have been removed from their posts for allegedly supporting Gulen.

Political opposition parties have also been targeted. The pro-Kurdish HDP, which won a surprising number of seats in the 2015 elections, has had many of its prominent members arrested on vague charges.

Hannibal Hanschke / Reuters People of the Turkish community living in Germany react after first news bulletins on the outcome of Turkey's referendum on the constitution in Berlin, Germany,.

Amid the government’s crackdown, Sunday’s vote had become less a referendum on constitutional reforms and more about Erdogan himself. In past years, a number of opposition parties had backed the idea of constitutional reform to remedy the country’s fractious coalition governments ― but as Erdogan grew more authoritarian and the new constitution focused heavily on the presidency, there was strong resistance against the changes.

Amid the political crackdown, however, many of Erdogan’s political opponents worried about reprisal if they were to speak out too forcefully against reforms. And in the end, the opposition campaign was unable to rival the strong push from Erdogan and the AKP.

“Against insurmountable odds, complete blanket coverage of the ‘yes’ campaign, there is stiff resistance to this among the Turkish population,” said Aaron Stein, a resident senior fellow at the Atlantic Council think tank, in the days leading up to the vote.

OZAN KOSE via Getty Images Turkish President Recep Tayyip Erdogan salutes official as he arrives at a polling station to vote in the referendum on expanding the powers of the president.

Even though the president has become increasingly repressive and has moved toward illiberal government, Erdogan still commands huge support.

But Sundays’ vote has left the country deeply divided. Voters in Turkey’s three biggest cities, Istanbul, Ankara and Izmir, appeared to have narrowly rejected the referendum. Residents of several Istanbul neighborhoods on Sunday night banged pots and pans from their windows to protests Erdogan’s claims of victory.

Erdogan is no longer counting on a wide range of voters to back his presidency, Stein explained. Instead, he relies on a loyal base of conservative supporters and some elements of the far-right.

“[Erdogan’s] weakness is that he now relies entirely on political polarization for popularity,” Stein said. “It’s no longer consensus-building across different factions in Turkey. It is a very right-wing, nationalist base that supports him.”

This story was updated throughout to reflect the results of Sunday’s vote.