As Williams, who was troubled by ankle problems earlier in the tournament, required treatment for back spasms and smashed her racquet as the match slipped away, Stephens held her nerve to win 3-6, 7-5, 6-4 in 2hr 17min.
"This is so crazy," said Stephens, who used to have Williams' poster on her bedroom wall. "I think I'll put a poster of myself up now."
Stephens, 19, regarded as Williams' successor as the force of women's tennis in the United States, now goes into a semi-final against world number one and defending champion Victoria Azarenka.
Williams, who had trumpeted her chance of winning the grand slam this year, said the defeat brought to an end one of the most painful major tournaments of her career.
"For a Grand Slam, absolutely," she said, when asked if it was the worst condition she'd been in.
"Oh my gosh. I'm almost relieved that it's over because there was only so much I could do. It's been a little difficult. I've been thrown a lot of balls these two weeks.
"Between the ankle, which is like this big every day," she said, gesturing, "and my back, which started hurting, there's been a lot of stuff."
The teenager was able to match her elder's trademark power in the opening exchanges, but errors crept in towards the end of the 28-minute first set.
Stephens played a dispirited opening game of the second set and Williams pounced. Appearing untroubled by the right ankle she rolled in the first round, Williams took a 2-0 lead before the youngster fought back.
Stephens showed glimpses of her much-hyped shot-making to break Williams' serve in the fourth game of the second set. Forehands started hitting the mark and her first serve was matching Williams' deliveries of 107 miles (172 kilometres) per hour.
She had a break point on Williams' serve at 3-2, only for the world number three to slide an ace down the T.
At 3-4, 0-30, Williams grimaced after hitting a backhand winner. Close to the net, she had to pull up quickly to avoid making contact with the net and losing the point.
"I even screamed on the court," she said. "I was like, aagh -- I totally locked up after that. It was a little painful. It was hard to rotate to the backhand. I'm already on anti-inflammatories for my ankle, so you can't do too much more."
She began hobbling between points, lost strength on her serve and Stephens broke for 5-3. Williams attempted to keep rallies short by hitting winners, and Stephens had an attack of nerves to lose serve when trying to level it at a set apiece.
Williams called for the trainer at 4-5, complaining of back spasms. Next game, she could barely serve but her groundstrokes remained potent.
She held serve to love as Stephens lost composure, but the teenager staved off a break points in the following game to lead 6-5, and won her second set point to take the match into a decider.
Games went on serve until Williams broke Stephens for a 4-3 lead. Williams' movement had improved to a significant degree, but Stephens broke back amid excruciating tension.
A final break of serve gave the teenager the biggest win of her career.
"Should be good," she said of her semi-final on Thursday. "I'll go out and do the thing again."