"This will be my last Test as head coach of the Australian cricket team," Lehmann told a press conference on the eve of the match.
"Saying goodbye to the players was the toughest thing I have ever had to do.
"I really felt for Steve and, as you see, I'm crying in front of the media. All the players are really hurting."
Speaking in Johannesburg soon after Lehmann's announcement, Cricket Australia (CA) chief executive James Sutherland said he wanted to pay tribute to the coach.
"He provided fantastic service and has been part of a very successful team that has achieved a lot during his time.
"I have seen firsthand the pride in which he has gone about his work and the love he has for the job and his incredible work ethic. He genuinely loves and respects his players."
Lehmann, who was due to leave the job after the 2019 Ashes series in England, is going despite being cleared of any role in the ball-tampering scandal that has rocked the sport.
His decision follows 12-month bans given to captain Smith and vice-captain David Warner for the roles they played in a plot to cheat in Cape Town last Saturday during the third Test.
Opening batsman Bancroft was banned for nine months for his part in the affair.
"As a team we know we've let so many people down and for that we're truly sorry," added the 48-year-old Lehmann.
"The players involved have been handed down very serious sentences and they know they must face the consequences. They have made a grave mistake but they are not bad people."
It's not just the players who have suffered, though.
"My family and I have copped a lot of abuse over the last week and it's taken its toll," said Lehmann.
"I am ultimately responsible for the culture of the team and I've been thinking about my position for a while.
"Despite telling media yesterday that I'm not resigning, after viewing Steve and Cameron's hurting, it is only fair that I make this decision."
Lehmann was hailed as a saviour when he took over in 2013, but critics now accuse him of overseeing a toxic culture that has dented the reputation of the famed Baggy Green cap.
After being appointed, Lehmann's response when asked to list his top three priorities was telling.
"Probably win, win, win, for a start," he told reporters.
Cricket Australia had other ideas.
"Discipline, consistency of behaviour and accountability for performance are all key ingredients that need to improve," Sutherland said at the time.
If part of Lehmann's brief was to improve the Australian team's behaviour, there is little doubt he has failed.
Senior Australian cricket commentator Jim Maxwell said the coach had to accept some blame for an "arrogant" team culture where certain players felt cheating was preferable to losing honourably.
"He's done a very good job with the side but has a very narrow view of the way players should conduct themselves," Maxwell said.
Lehmann became national coach after Australia sacked the first foreigner to hold the post, South African Mickey Arthur, on the eve of an Ashes series.
A respected former batsman who played 27 Tests and 117 one-day internationals for Australia, Lehmann was seen as an antidote to disciplinarian Arthur.
Australia lost Lehmann's first Ashes series in charge but later in 2013, after he had stamped his mark on the team, they crushed England 5-0.
He won 30 Tests as coach, lost 19 and drew eight.