The Springboks finished the game without full-back Percy Montgomery, who had missed four kicks at goal before receiving his second yellow card and his marching orders 10 minutes from time for a high tackle on Shane Williams.
Ceri Sweeney crossed for a consolation score, but by then the game was realistically over.
Two weekends ago New Zealand's Rico Gear left Cardiff with a hat-trick of tries. Habana could not quite match that feat, but he scored once in each half - taking his tally to 15 in 14 Tests - and had a hand in the third.
Sonny Parker failed to deal with Habana's grubber kick and Conrad Jantjes simply had to fall on the ball to score.
Wales were not even given the pleasure of finishing the game with gusto as replacement Danie Roussouw touched down for South Africa's fourth try in the last minute.
The home side started nervously. Michael Owen dropped the kick-off, referee Stuart Dickinson penalised them at the scrum and Montgomery, formerly of Newport, booted South Africa into a 90-second lead.
There was nothing timid about the Welsh defence, which was fast moving and powerful, but they were struggling to release the pressure early on.
And after one scare down the left it finally told. South Africa worked the overlap and Habana dived over.
Wales responded by mounting their first concerted attack of the game - Gareth Thomas, playing in the centre, led the charge deep into South African territory - and eventually earning a penalty which Simon Jones converted, but Montgomery responded in kind.
Jones made no mistake with his second penalty on the half hour after a careless late shot from Montgomery on Sonny Parker and there were signs that Wales' electric brand of rugby was sparking into life.
Shane Williams and James were combining well but the Welsh handling was rusty and the final pass too often went begging. Wales entered half-time trailing 11-6 but in good heart.
South Africa started strongly, drawing in the Welsh defence before pinging the ball wide where left Habana waited in glorious amounts of space to score his second.
Montgomery missed the conversion and after Jones had kept Welsh hopes alive with his third penalty the South African full-back was sin-binned for tackling Shane Williams off the ball.
But Welsh prop Chris Horsman followed for punching and just before the hour South Africa delivered the killer blow. Parker failed to deal with Habana's grubber kick, Jantjes fell onto the loose ball and Bosman converted to put Wales 23-9 ahead.
Shane Williams was causing South Africa the most problems and his dart for the corner was halted only by a high tackle from Montgomery.
The full-back was sent-off for a second yellow card and Wales took maximum advantage with Williams sending replacement Sweeney over for the try.
But Wales were not even to have the final say and Roussouw squeezed over under the posts in the last minute.