Wayne Rooney, who should have seen red for lashing out at Jordon Mutch during the early exchanges, had put United ahead before Fraizer Campbell, who later struck the crossbar with a superb chip, equalised.
Rooney's corner allowed Patrice Evra to head home and put United back in front on the stroke of half-time, but Kim found the net with a thumping header at the start of four extra minutes from Peter Whittingham's free-kick.
United's unbeaten run now extends to 10 games but they missed out on the chance to climb into the top four and an ineffectual display, particularly in midfield, indicates there is still plenty of work ahead for manager David Moyes.
It could arguably have been even worse for the defending Premier League champions had Rooney been sent off, as he ought to have been, by referee Neil Swarbrick in the eighth minute.
The England forward kicked Cardiff midfielder Mutch before lashing out with his left hand as his run was blocked off. Swarbrick deemed a yellow card to be strong enough punishment and it was almost inevitable that it was Rooney who opened the scoring in the 15th minute.
Ben Turner gifted Antonio Valencia possession and when the winger's ball ran through to Rooney, via a flick from Javier Hernandez, he turned and shot beyond David Marshall with the aid of a deflection off Gary Medel's boot.
Marshall then pushed out a goalbound Marouane Fellaini header at the back post.
Cardiff needed to settle and they slowly but surely found a foothold before hitting back in the 33rd minute.
Mutch was the architect with a lovely pass for Campbell to race on to and guide past the advancing David De Gea for his first goal since August.
Campbell volleyed over a few minutes later, with Don Cowie prodding wide from an Andrew Taylor pull-back as the home side grew in belief.
But they were punished right on half-time for some poor set-piece defending. Rooney swung in the corner and Medel simply allowed Evra to wander away from him and head in at the near post.
They almost came undone from another Rooney delivery early in the second half but Marshall made an agile save from Fellaini's glancing header, before blocking Chris Smalling's more powerful effort from the resulting corner.
Having survived those scares, Cardiff came close to a leveller. Rooney could not control Tom Cleverley's poor pass and Campbell pounced to chip De Gea, only to see the ball come back off the bar.
Cleverley headed narrowly over his own bar before Ryan Giggs came on in place of Hernandez to face his hometown club for the first time, making them his 117th opponents as a United player, but he received a surprisingly mixed reception from the home fans.
Substitute Danny Welbeck should have made the game safe for United after a nice link-up with Rooney, but fired over the bar, before Cleverley was booked for a wild and ugly challenge on Whittingham.
Welbeck's miss proved costly as Kim got ahead of his marker to head beyond De Gea and spark delirious Cardiff celebrations.
United could yet have snatched a winner, but Rooney's attempted lay-off for Welbeck was under-hit, and Marshall gratefully pounced on the loose ball.