The 27-year-old South African, from the Western Cape coastal town of Mossel Bay, started the second round in second place at seven-under par, two behind the hotshot young Ulsterman.
But three birdies in a row from the fifth hole, despite heavy rain, saw him move ahead as he went out in 33.
Oosthuizen followed up with four birdies against two bogeys on the back nine to come in with a 67, which gave him the overall lead in the clubhouse at 12-under par.
The Oosthuizen charge came out of the blue, as he had failed to make the cut in his three previous Open campaigns.
But his first top-tier win at the Andalucia Open in March provided him with a much-needed confidence booster to take his game onto a higher level.
"I think the win earlier in the year in Spain got my confidence going quite a bit, and I've been playing well all year, really," said Oosthuizen, who credits South African star Ernie Els with helping him bridge the gap between a struggling farming family background to the life of a professional golfer.
"You know, it's just a matter of making crucial putts, I think, and yesterday I made a few crucial ones. Today I missed a few, but I made good ones, as well.
"I'm very confident the way I'm playing I'm hitting it well, and you know, I'm just having a lot of fun, really."
Oosthuizen's 67 was all the more remarkable in that the morning play was marked by heavy downpours that soaked the Old Course and sent spectators scurrying for cover.
Also closing in on the 21-year-old McIlroy was England's Paul Casey, who was at eight-under through 14 after firing five birdies in his first eight holes, while 1989 Open winner Mark Calcavecchia was at seven under after carding a fine five-under 67.
European number one Lee Westwood stayed in contention at six-under through 13 holes, while world number two Phil Mickelson moved to two-under through 11 thanks to an eagle at the fifth.
If it was impressive play in the wet conditions from the early starters, the big question was could McIlroy reproduce the stunning form he showed on Thursday when he overwhelmed the Old Course.
His nine-under par 63 was the lowest first-round score in the 150-year history of the championship and matched the best score ever recorded in a major.
McIlroy was one of 45 players in the field of 156 to better 70, although that was five fewer than at Turnberry last year, when conditions toughened considerably over the weekend.
The early starters on Friday were once again greeted by benign seaside conditions and little wind to trouble their progress around the historic links course.
But that changed dramatically after about an hour's play as heavy rain began to fall and temperatures plunged.
McIlroy, looking to make it back-to-back major wins for Ulstermen following close friend Graeme McDowell's breakthrough win in the US Open at Pebble Beach last month, said he was hoping for more testing conditions.
"I wouldn't mind the wind to blow a bit, just so long as it stays dry," he said after recording his best ever score at St Andrews.
"It's very special this year being at St Andrews, 150 years and everything. I think it deserves a bit of good weather. I don't mind a bit of wind, but as long as it stays dry."
Tied on six-under after the first round were five players, including born-again John Daly, who lit up the opening day at the Home of Golf with his best display in years and the kaleidoscopic nature of his trousers.
Daly was due out around midday, with tournament favourite Tiger Woods not in action until 2:20 p.m.
Woods was contented with his opening effort of 67, which included just the one bogey, again at the Road Hole.
"I'm getting better every week. I'm hitting shots that I haven't hit in a long time. It's building," was his assessment of his current form.
The fallen American superstar is aiming to become the first player to win the Open at St Andrews three times in a row and he is also looking to record his 15th win in a major and close in on the record 18 titles held by Jack Nicklaus.