Scotland skipper Bryan Redpath was bitterly disappointed to lose out to South Africa in the first Test in Durban but can take heart from a spirited display from his side.
Redpath saw his side go very close to beating the Boks
The visitors took advantage of some sloppy play from the Springboks to move into a 25-12 lead going into the final quarter.
But the home side hit back strongly to finish 29-25 winners.
Tries by Stefan Terblanche and Trevor Halstead within 11 minutes denied the Scots, who were 21-6 winners over South Africa at Murrayfield last November.
But the Springboks had to withstand fierce pressure at the death as Scotland pushed forward with purpose.
Scotland were awarded numerous penalties in stoppage time and Nathan Hines was punished for a knock-on after crossing the try line in the final seconds.
Jason White, Andy Craig and Chris Paterson were the try-scorers for Scotland.
Scrum-half Redpath said: "I'm disappointed, but all credit to South Africa. We feared they would come at us in the closing stages and so it proved.
"It is disappointing to have let it slip like that. They took their opportunities late in the game and secured the win.
"We came here to learn and improve our skills and I believe we coped well given that we are a small rugby nation and South Africa are a big one. I hope we do better next weekend."
Scotland coach Ian McGeechan was also pleased with some aspects of the game but fears the home side will be in better shape for next weekend's second and final Test at Ellis Park in Johannesburg.
"The signs are there that things are starting to fall into place for us," said McGeechan.
"But we have to learn to hold onto leads against big teams. Make no mistake, they will be even stronger next week."
Joost van der Westhuizen returned to captain the South Africans for the first time since 1999 and was not pleased by his side's display.
"We did not play well because we kept surrendering first-phase possession and were over eager," said the scrum-half, who was sent to the sin bin with 30 seconds left for a professional foul.
"The boys must learn to catch the ball instead of snatching at it, but they did display tremendous character in the closing stages.
However, there is a lot to do ahead of the World Cup."