Turkey's ruling Justice and Development Party (AKP) has won a critical parliamentary election, regaining the majority it lost in June.

With almost all ballots counted, the state-run Anadolu news agency said the AKP had won 49.4% of the vote, with the main opposition CHP on 25.4%.

President Recep Tayyip Erdogan said voters had "shown that they prefer action and development to controversy".

The nationalist MHP will also take seats in Ankara.

In a statement, President Erdogan said the electorate had "given proof of their strong desire for the unity and integrity" of Turkey.

Early on Monday, he called on the world to respect Turkey's national will.

Mr Erdogan called the vote after the AKP lost its parliamentary majority for the first time in 13 years in June and attempts to form a coalition government failed.

Speaking from the balcony of the AKP headquarters in the capital, Prime Minister Ahmet Davutoglu welcomed the new result, saying: "You saw the dirty games played in our country, and you have changed the game".

With almost all of the results counted, the AKP had won substantially more than the 276 seats needed in order to form a government alone.

However, it fell 14 seats short of the number needed to call a referendum on changing the constitution and increasing the powers of the president, AKP founder Recep Tayyip Erdogan.

With 60 more seats, the government would have been able to bring in those changes without a referendum.

The AKP's opponents had said the vote was a chance to curb what it sees as the increasingly authoritarian tendencies of Mr Erdogan.

Analysis: Mark Lowen, BBC News, Ankara

image copyright Getty Images

After its shock landslide victory, the AK Party today begins the process of forming a new government, regaining the majority it lost in the election in June.

It almost equalled its best ever result, swaying voters with its message of stability after weeks of violence with the PKK Kurdish rebels.

There is now the hope that the two sides may be spurred to return to peace talks.

The Turkish currency, the lira, has rallied after a shaky few months, but an economic crisis could still loom.

There are also fears that the political polarisation stoked by President Erdogan could deepen and a clampdown on free speech worsen as the AK Party feels emboldened.

Since elections in June, a ceasefire between the Turkish army and militants from the Kurdistan Workers Party (PKK) has collapsed after a suicide bombing in July by suspected Islamic State (IS) militants.

The attack near the border with Syria killed more than 30 Kurds.

Turkey then suffered its deadliest attack in its modern history when more than 100 people were killed after a peace rally in Ankara attended by mainly left-wing demonstrators, including many HDP supporters, was targeted by two suicide bombers.

The government said they were linked to IS.

media caption There were violent protests in the mainly Kurdish city of Diyarbakir after the result

Critics have accused Mr Erdogan of renewing violence to curb support for the HDP - something the government denies.

One senior official from the HDP told Reuters news agency the partial results were "disappointing".

The HDP won 10.7% of the vote - enough to give it 59 parliamentary seats, 21 fewer than it claimed in June's election.

The party cancelled rallies following the Ankara attack, and its co-chairman Selahettin Demirtas said on Sunday that it had not been "a fair or equal election".

Clashes were reported in the mainly Kurdish city of Diyarbakir as the results were being counted. Reuters said police had fired tear gas at protesters throwing stones.