Two tries from Handre Pollard and one from Francois Hougaard gave the hosts an eight-point advantage at the interval but the All Blacks fought back in typically determined fashion through Ben Smith and Dane Coles.
Those tries meant the visitors held a one point lead as Lambie stepped up to nervelessly slot the winning penalty through the uprights and deny Richie McCaw a win on his record-breaking 134th appearance for New Zealand.
For both teams this was their final encounter in Rugby Championship - a competition comfortably won by the All Blacks.
But while Hansen admits the defeat was a bitter blow, he credited the Springboks for their performance and is adamant that his troops will use the loss as a learning curve.
"This team hates losing. It sucks really," said Hansen. "Every now and then you've got to do it - we'll learn some things from it, as we do whether we win or lose.
"I am proud of the way we came back and the guys played really well to give us a chance after we had been under so much pressure in the early part of the game.
"But in the end you have to congratulate the Boks for getting over the line, and I think this was a match where the right team won.
"We didn't start as well as we would have liked, and had no momentum in the first half. We showed great composure and belief in coming back, and our defence was magnificent, but in the end the Boks were too good for us.
"In the end it came down to a 55 metre penalty, and full credit to Lambie for kicking it under enormous pressure."