Wozniacki, of Denmark, was ahead 3-0 when Victoria Azarenka packed it in after taking a lengthy medical timeout to receive treatment for an injury to the left side of her hip.
The eighth seed Azarenka suffered the setback just 10 minutes into the match on the second point of the third game while stretching to try and return a shot.
World number one Wozniacki, who is good friends with Azarenka, said she was sorry to have to win that way.
"Victoria is one of my best friends on the tour, and to see her in pain on the court and to see her get injured was not nice for sure," Wozniacki said. "I would like to have won it in another way, but I'm through to the semi-finals."
Wozniacki moves on to play three-time grand slam champion Sharapova who defeated China's Peng Shuai 6-2, 5-7, 6-3 in a two-hour, 22-minute marathon quarter-final.
Wozniacki beat Azarenka for the fourth time in six career meetings and has now reached the semi-finals in her last four tournaments.
"I have had so many good results lately," Wozniacki said. "Everything is working out for me.
"I am living the dream I have had since I was a little girl. This is what I dreamed of playing in these stadiums."
Azarenka, 21, was hoping to reach her first semi-final of the year before she got hurt.
The drama took place in the third game of the first set after Wozniacki served to the win the first game then broke Azarenka in the second game to go up 2-0.
Halfway through the third game, the Belarussian was stretching to hit a return shot behind the baseline when she landed hard on her left leg and grimaced in pain.
She covered her face with her hand and dropped to all fours before gingerly making her way over to her chair and calling for the trainer. The trainer put towels on the court and massaged Azarenka's upper leg before taking her into the medical room.
Azarenka returned 14 minutes later, played the final two points of the game and then after consulting her coach packed it in.
Sharapova won her quarter-final despite committing 13 double faults and winning just 27 per cent of her second-serve points.
Neither player could hold serve at the start of the deciding set but then Sharapova found a spark in the sixth game to hold serve for the first time in the set and level the score at 3-3. Sharapova also won the next three games to take the match.
Sharapova, who called for her coach to come down to the court several times, broke Peng's serve four times in the third set, including the final game of the match to earn her ninth match win of the season to go with three losses.
"I played well in the first set and a half and then my level dropped," Sharapova said. "It was important to stay tough out there because you know the match isn't over until the last point."
Sharapova, who is the lone former Indian Wells champion left in the women's draw, now holds a 2-1 edge over Peng in career matches.
"Was really happy to into the quarterfinal here, but Maria is a tough match," Peng said. "In the third set I have chance, but she play well."
What the stars mean:
★ Poor ★ ★ Promising ★★★ Good ★★★★ Very good ★★★★★ Exceptional