Schwartzel, who had led since the halfway point, overcame sickness and shoulder and back pains to finish with an overall 19-under 265 at the Club de Campo golf course.
The 24-year-old golfer used two birdies early on to pad his overnight lead of one shot, before getting another three after the turn. Schwartzel's last European Tour victory also came in the Spanish capital at last year's Spanish Open.
"I woke up this morning and felt a lot better than I have been feeling,'' Schwartzel said. "I thought I ground it out nicely all week. I just managed to keep it going today.''
Scwartzel took the initiative at the par-5 No. 7 after a precise chip from the trees to within three feet allowed the South African to birdie. Gonzalez slid his own birdie putt from five feet wide to drop three shots back.
Gonzalez would sink his first birdie two holes later but down the stretch failed to emulate Saturday's low round of 62 that moved him into contention. The Argentine finished at 16-under after his final round score of 68.
Pablo Larrazabal (67) was a further shot back in third at 15-under, one shot up on fellow Spaniard Alvaro Quiros (64) and England's Robert Rock (64).
Federer to play Madrid Masters after layoff
Madrid Set For Last-Gasp Villa Bid - Report
Nadal plays to keep No. 1