Sharapova was cruising against Agnieszka Radwanska before allowing the third-seeded Pole to break back in the second set. But the eighth-ranked Russian recovered to secure a 6-1, 6-4 win.
Earlier, Halep rallied in the hot conditions to dispatch former champion Petra Kvitova 6-7 (4), 6-3, 6-2.
"She's having a great year so it's going to be an extremely difficult match," Sharapova said of Halep.
Despite a few blips, Sharapova has been steady all week and has lost just three times on clay since the 2011 French Open. All three of those losses came against Serena Williams, the two-time defending champion in Madrid who withdrew with a left thigh injury on Friday.
Kvitova, the 2011 winner, looked on course for victory before unforced errors and the rising temperatures took their toll.
The Czech was 2-0 up in the second set and cruising against Halep, who was visibly frustrated after a late call went against her during the first-set tiebreaker.
But Kvitova hit 66 unforced errors and that inconsistency caught up with her as Halep recovered, with the now composed Romanian hitting 22 winners and breaking Kvitova four times over the last two sets.
Kvitova struggled in the final set, looking sapped of energy by the end of a match that lasted more than 2½ hours.
"It's been an amazing week for me, I feel very well here in Madrid," said the fifth-ranked Halep, who reached her first Masters series final. "I played really well, I was striking the ball really well."
Sharapova hit 28 winners to four for Radwanska, who netted a forehand on match point to be broken for a seventh time.