A two-time Madrid Open champion, Halep upset No. 2-ranked Paula Badosa in the second round.
The 21st-ranked Halep converted three of her five break opportunities to close out the center-court match against the 16th-ranked Gauff. She rallied from a break down in the second set, winning the last five games.
Halep won in Madrid in 2016 and 2017, and was runner-up in 2014 and 2019. She has 30 main draw wins, behind only the 31 she has at the Australian Open and Roland Garros.
"It means a lot because I feel great,'' Halep said. "I like the conditions. The people are very nice to me. I will always have a warm welcome. Everyone makes me feel like home.''
Halep will face eighth-seeded Ons Jabeur, who defeated Belinda Bencic 6-2, 3-6, 6-3 in a match interrupted by rain after the second set. The 10th-ranked Jabeur, the only top-10 woman left in the draw, lost to Bencic at this stage in Madrid last year, and also in the final in Charleston last month.
"I came here to take my revenge,'' Jabeur said. "I wish I played like that in the final in Charleston, to be honest.''
Information from The Associated Press was used in this report.