The Romanian top seed wrapped up victory in an hour and 11 minutes, hitting 23 winners and limiting herself to 18 unforced errors as she ended her Belgian opponent's 13-match winning streak.
Mertens, who has won titles in Morocco and Switzerland this year, previous form deserted her as she struggled to cope with Halep's combination of power, guile and relentless court coverage.
She found her feet at the start of the second set and fought gamely to the end, saving four match points while serving in the final game before netting a routine forehand to cough up a fifth and conceding the match with a tame double fault.
WTA Madrid
Bertens eases into Madrid final at expense of Garcia, Kvitova beats Pliskova
11/05/2018 AT 17:30
Halep will face Kristyna Pliskova in the last-16 after the Czech beat Spaniard Sara Sorribes Tormo 7-5 6-2.
Petra Kvitova, who is seeded 10th in Madrid, edged out wild card Monica Puig 6-3 7-6(8) in the day's early encounter and will face either Belarusian Aliaksandra Sasnovich or Estonia's Anett Kontaveit in the next round.
Kvitova dished out nine aces, but made an equal number of double faults as she held on to extend her winning streak to seven matches despite her opponent's aggressive brand of tennis.
The two went toe-to-toe as the advantage swung back and forth, but Puig paid the price for not getting enough first serves across the net and failing to take her opportunities when they arose, allowing the Czech to prevail.
With the score tied at 8-8 in the second-set tiebreak, Kvitova secured a match point with an ace, before sealing victory with a powerful forehand.
WTA Madrid
Bertens ousts Sharapova as defending champion Halep crashes out
10/05/2018 AT 16:07
WTA Madrid
Wozniacki falls in Madrid, Halep marches on
09/05/2018 AT 14:17