Mr Qalibaf called on his supporters to back conservative cleric Ebrahim Raisi against the incumbent Hassan Rouhani, a moderate who is seeking a second term.
A victory for Mr Raisi on Friday was vital for "the preservation of the interests of the people, the revolution and the country", he warned.
Mr Qalibaf had been under pressure from the clerical establishment to drop out.
Hardliners reportedly feared the anti-Rouhani vote would be split and make a second round run-off more likely.
In the last election in 2013, the former Revolutionary Guards commander and police chief came a distant second to Mr Rouhani with 16.5% of the vote.
In a statement published by state media on Monday, Mr Qalibaf wrote that he was withdrawing his candidacy in an attempt to put an end to President Rouhani's "inefficient and impotent" administration.
"A fundamental and crucial decision must be taken for the unity of the revolutionary front," he explained.
"To protect this great ideal, I ask all of my supporters across the country to offer all of their support to the success of our dear brother, Ebrahim Raisi."
Mr Raisi is a close ally of Supreme Leader Ayatollah Ali Khamenei.
The former prosecutor is currently head of a multi-billion-dollar charitable foundation that manages donations to Iran's holiest shrine in the city of Mashhad.
Unofficial polls suggest that Mr Rouhani will win the election, but it is not clear if he will receive more than 50% of the vote and avoid a run-off on 26 May.
The president has faced a significant challenge from conservatives because the landmark nuclear deal with world powers that he negotiated in 2015 has not triggered the economic recovery he predicted.
Mr Raisi has promised to build a self-sufficient "resistance economy", create millions of jobs and triple cash hand-outs to the poor.
Vice-President Eshaq Jahangiri and the two other men whose candidacies were approved by the Guardian Council last month - reformist Mostafa Hashemitaba and conservative Mostafa Mirsalim - are also thought to be likely to withdraw before the election.
Tehran's hardline mayor, Mohammad Baqer Qalibaf, has withdrawn from Iran's presidential election.