The opposition boycotted the vote, saying Turkey's secular state is at risk through encroaching Islamization.
It was the second time in the last week that the Turkish parliament failed to elect a new president.
The Islamic-rooted AK party of Prime Minister Recep Tayyip Erdogan failed to secure the presence of two-thirds of the deputies, which is needed to make the voting process valid.
Opposition parties refused to attend the parliamentary session in protest to Gul's candidacy.
Gul announced immediately afterward that he will withdraw his candidacy.
There has been increasing pressure in recent weeks from the public and the military, which has threatened to intervene to ensure secularism is maintained.
Tens of thousands of people took to the streets of several cities in western Turkey on May 5 to protest against a Gul presidency, which they said would be a threat to Turkey's secular state.
Ahmet Bulut demonstrated in the city of Manisa.
"We're here to protect the republic and teach [the government] a lesson," he said. "I hope they learn their lesson."
Earlier pro-secular demonstrations in the country's largest city, Istanbul, and the capital, Ankara, drew more than 1 million people.
The next president is now expected to be elected after an early general election for a new parliament on July 22.
Although the post is largely ceremonial, the president can veto legislation.