The candidate of Turkey's ruling party, Abdullah Gul, has failed to win the presidency in a second round of voting.
He fell short of a two-thirds majority of votes cast by MPs, but is expected to win in a third round next week, when only a simple majority is needed.
Mr Gul's candidacy has been highly controversial, sparking a political crisis that led to early elections.
But since his AK Party won those polls convincingly, correspondents say it has the authority to push its man through.
The country's military and secular establishment have voiced their opposition to Mr Gul, a devout Muslim whom they believe has an Islamist agenda.
Mr Gul, currently the foreign minister, denies that, and has vowed to remain loyal to the country's secular constitution.
President chosen by 550 MPs
Two-thirds majority (367) needed to win in first or second round
Simple majority (276) needed if the contest reaches later rounds
Q&A: Presidency battle
Profile: Abdullah Gul
Mrs Gul's fashion makeover
The president is elected by parliament, where the AK Party has 340 of the 550 seats.
In the vote Mr Gul secured 337 votes - falling short of the two-thirds majority needed to win outright. In the first round on Monday he got 341 votes.
The other two candidates - Sabahattin Cakmakoglu from the right-wing Nationalist Action Party, and Tayfun Icli from the centre-left Democratic Left Party - failed to mount a serious challenge.
In the third round, a candidate needs only a simple majority to win - leading analysts to predict confidently that Mr Gul will be declared president next Tuesday, 28 August.
The foreign minister's candidacy in an earlier presidential vote in April prompted a boycott by the opposition, street protests and a warning from the military that it would not allow his election.
The army has kept quiet this time, but there are still fears among secularists that by controlling the presidency as well as the government, the Islamist-rooted AKP will be able to push through reforms undermining the secular constitution.
The military will be watching for his slightest slip, says the BBC's Sarah Rainsford in Istanbul.
And there is already furious debate because Mr Gul's wife wears the Islamic headscarf.
It is seen by some as a symbol of political Islam and is banned in all state institutions, including the presidential palace.