The 37-year-old American dismantled Halep's game to race through the opening set in 20 minutes.
Romania's Halep, 27, recovered in the second, breaking in what proved to be the final game.
Williams, seeded 16th, saved three break points for 3-3 in the decider, crucially winning the next game to seize control.
The 23-time Grand Slam champion comfortably held her next service game to edge closer, then served out for victory over last year's runner-up in one hour and 47 minutes.
Triumphantly punching the air with both arms as she gave a steely stare towards her box, Williams showed how much relief she felt at beating the world number one.
"It was an intense match and there were some incredible points, but I love being here," she said.
Williams, searching for her first Grand Slam title since coming back from pregnancy last year, has now won nine of her 10 meetings with Halep.
The seven-time champion will meet Czech seventh seed Karolina Pliskova, who beat Spain's two-time Grand Slam winner Garbine Muguruza earlier on Monday, in the last eight.
If Williams goes on to extend her record number of victories in Melbourne, she will equal Australian Margaret Court's all-time tally of 24 Grand Slam titles.
From the moment these two players were drawn in the same section of the Australian Open - and projected to meet in the last 16 - there had been a sense of anticipation among tennis fans: Williams, the long-time former world number one, taking on the current holder, Halep.
And a match containing fight, drama and high-quality tennis from both players did not disappoint.
Halep admitted before the match that Williams was still the "best player in the world", and Williams may have proved it with her first win over a number-one ranked player since beating Victoria Azarenka in 2013.
"I really needed to elevate my game," Williams said.
"She's the number one player in the world and there's a reason why. She's a great player."
Williams left the Melbourne crowd stunned with the ease with which she dismantled Halep's game, particularly the Romanian's second serve, in a one-sided opening set.
Halep, who won her maiden Grand Slam at last year's French Open, broke Williams' serve to love in the first game - which included a double fault on game point - before the American settled down.
Williams allowed Halep just nine more points on her way to a one-set lead.
On that evidence, those inside Laver who thought the second set would be a formality could have been forgiven.
Yet Halep summoned every bit of her fighting qualities to stay on serve in the second, cutting down the unforced errors and making Williams move more to great success.
With the set still delicately poised, Halep won eight of the final 11 points to force a decider.
That was equally hard fought, Halep staving off Williams in a lengthy opening game, before a sixth that proved pivotal.
Halep earned three break points - her first opportunities of the final set - but a 171km/h serve down the middle, followed by a weak forehand from the Romanian and another booming serve, saw the chance slip.
That allowed Williams to take control at the crucial moment, Halep making another unforced error with a forehand to hand over the break.
"I'm such a fighter. I never give up. It's something that's innate," Williams said.
"It's a miracle I'm here and I get to do something I enjoy."