By Sarah Rainsford
BBC News, Istanbul
Turkey's highest court has ruled that a disputed constitutional reforms package passed by the government is valid.
The AKP move to introduce its own candidate caused a standoff
The move, a blow for the current president and the main opposition party, paves the way for Turkey to hold direct elections for the presidency.
Both the president and main opposition party had applied to the court to annul the reforms.
They had complained that the changes were adopted in haste and threatened the country's stability.
The ruling AKP moved to introduce a direct presidential ballot to end the standoff caused when it tried to get its own candidate, Abdullah Gul, elected president through parliament.
The opposition boycotted the vote, claiming the former Islamist Mr Gul was a threat to the secular regime.
The decision to approve the reforms was a surprise ruling in favour of the government from Turkey's highest court, the latest move in an ongoing battle between the secular establishment and the former Islamist AKP over who controls the presidency.
In May, the same court annulled the presidential election on a technicality and stopped the government's candidate from taking office, so the ruling AKP moved to change the system and let the people, not parliament, choose the president.
The staunchly secular opposition and the current president claimed that would disturb the balance of power but this time the judges ruled 6-5 against them.
A referendum is now likely in autumn when the Turkish people will vote on whether they want to choose their own president.
The majority are expected to vote in favour, in which case an AKP candidate would have a strong chance of winning, but first there is the parliamentary election later this month.
If the AKP secures another majority, the referendum is likely to go ahead.
If not, the next parliament could decide to elect a president itself and keep an AKP candidate out of office for another seven years at least.