Lula had been the frontrunner despite being in jail for a corruption conviction and despite the top electoral court barring his candidacy.
With the deadline for the registration of candidates only hours away, he threw his weight behind his Workers' Party colleague Fernando Haddad.
The election is on 7 October.
It has been a tumultuous election campaign dominated by Lula's legal battles and the stabbing last week of Jair Bolsonaro, the far-right candidate who is second in the polls behind Lula.
Mr Bolsonaro was attacked by a lone assailant during a campaign rally and is still in hospital..
What has happened with Lula?
With the clock ticking down on a deadline for candidates to be registered, senior members of the Workers' Party gathered in front of the police headquarters where Lula, 72, is serving a 12-year prison sentence for corruption.
The party's founder, Luiz Eduardo Greenhalgh, then read out a letter written by Lula in his cell.
In it, Lula, who governed from January 2003 until December 2010, said that he had been "unjustly imprisoned" before asking "all who would vote for me to vote for our friend Fernando Haddad for president".
Why was Lula barred?
Lula was barred from running for the presidency under a 2010 law dubbed "Clean Slate". It prohibits those who have a criminal conviction which has been upheld on appeal from running for public office.
In July 2017, Lula was found guilty of accepting an upgrade to a beachfront flat as a bribe from an engineering firm involved in a major corruption scheme.
Lula has always denied any wrongdoing and appealed against the verdict. The appeal was rejected and Lula was given 24 hours to turn himself in.
From his cell, Lula has continued the legal fight against his conviction and the ban which prevents him from running for public office.
Why did he finally give up?
The decision was made less than two weeks after Brazil's top electoral court ruled that he was "ineligible" to run for the presidency.
Lula's legal team has appealed against that decision and the Supreme Court is still due to rule on it.
But after a Workers' Party request to extend the deadline to register presidential candidates from the 11 September to 17 September was rejected, its leadership felt it had to act.
Not registering Mr Haddad meant that if Lula's appeal were to fail, the party could have been left without a presidential candidate altogether.
After Lula backed Mr Haddad in his letter, the party registered him as its new candidate with just hours to spare.
What next?
The Workers' Party hopes people who were going to vote for Lula will now vote for Mr Haddad.
Lula left office with record approval ratings in 2010 and despite his imprisonment, almost 40% of people asked by polling firm Datafolha said they would vote for him.
Mr Haddad, on the other hand, is not very well known outside of São Paulo, where he was mayor from 2013 to 2017.
In his letter, Lula said that Mr Haddad "will be my representative in this battle". "Our name is now Haddad!" he wrote.
In its first TV spot since Mr Haddad became its presidential candidate, the party also stressed the links between the two men.
Both Lula and Mr Haddad appear for the same amount of time and rather than talking about himself, Mr Haddad praises Lula and his achievements.
BBC
More about: Brazil