Lee's hat-trick, the fourth in World Cup history, reduced Kenya to three for three after being put in.
They recovered to reach 174 for eight but some brutal hitting by Adam Gilchrist, with a 43-ball 67, seemed to have set Australia on course to an easy win in the day-night encounter.
Left-armer Karim, however, at 39 the oldest player left in the tournament, then took three wickets in his first two overs to reduce Ricky Ponting's side to 117 for five.
Karim finished with three for seven from 8.2 overs and it took some cautious batting from Andrew Symonds (33 not out) to end Kenya's dream of an upset as the world champions reached their target with 18.2 overs in hand.
The Super Six game had not great meaning, with both sides already qualified for the semi-finals, where Australia will play Sri Lankan and Kenya will take on India.
The Kenyans' spirited performance, however, served as excellent preparation for their semi-final at the same venue on Thursday.
The chances of the game lasting until the floodlights came on looked remote when Lee took his hat-trick, becoming the second man after Sri Lanka's Chaminda Vaas to do it in this tournament.
It was the 17th in one-day internationals and the fourth in World Cup history after Chetan Sharma of India, Pakistan's Saqlain Mushtaq and Vaas.
Continuing the lethal form that brought him five wickets for three runs in 15 balls at the end of the last match against New Zealand, Lee struck with the last three balls of his second over.
IN AGONY
First he bowled Kennedy Otieno with a sharply rising ball that cannoned into the stumps off the batsman's left elbow and left Otieno writhing on the ground in agony.
X-rays revealed no fracture and he is expected to be fit in time for Thursday's game.
Lee's second wicket came via a more orthodox route as Brijal Patel edged a forward push to Ricky Ponting at second slip, then Lee found the perfect yorker to bowl David Obuya.
Kenya recovered thanks to captain Steve Tikolo (51), opener Ravindu Shah (46) and middle order batsman Hitesh Modi (39 not out).
Tikolo and Shah added 79 for the fourth wicket in 23 overs.
Shah failed to reach his fifty when he top-edged a sweep at left-arm spinner Brad Hogg. Tikolo reached that landmark, his first of the tournament, in 97 balls with five fours.
Kenya, though, subsided from 131 for four to 144 for eight before Modi and Martin Suji added an unbroken 30 in six overs.
Kenya's target looked minute as Gilchrist went to work, hitting nine fours and three sixes.
His hitting included 16 off an over from seamer Martin Suji and 18 from the first over bowled by leg-spinner Collins Obuya as he passed fifty for the third time in this World Cup.
However his dismissal, caught behind by David Obuya, and the introduction of Karim changed the landscape and briefly gave Kenya a glimpse of a famous victory.
PONTING BAMBOOZLED
Karim, who captained the side in the 1999 World Cup bamboozled Ponting (18) as he trapped him leg before wicket for 18 in his first over.
Then in his next over Lehmann (2) was caught behind by stand-in wicketkeeper David Obuya and three balls later Brad Hogg (0) drove back a low return chance.
Symonds, back in the side after missing the previous two games with a groin injury, restored Australia's control and with Ian Harvey (28 not out) added an unbroken 61 for the sixth wicket to seal the win.
Australia play Sri Lanka in Port Elizabeth on Tuesday.