Madsen had looked an unlikely winner earlier in the day but home favourites Hennie Otto and Charl Schwartzel both squandered three-shot leads to gift him the title.
He carded a bogey-free five-under-par 67 in his fourth round for a total of 269, two shots ahead of South Africans Jbe Kruger and Otto.
With his father watching from the gallery, the 25-year-old Madsen beat his previous best finish of second at the Madeira Open in May.
"It's been an amazing day, it hasn't sunk in. Coming down here I didn't expect to win," Madsen said at the trophy presentation.
"Schwartzel looked like he was just going to go off... I was just trying to hang on and see if I could stay within two or three shots. Unfortunately for him he struggled on a couple of holes and got some bad breaks. Luckily for me I was there to capitalise."
Overnight leader Schwartzel, searching for his first win in his home championship, carded a disappointing final-round 71, which included a triple bogey on the sixth hole and a double on the 10th, to finish in tied fourth with Italian Marco Crespi.
Otto, who led by three shots going into the final four holes, dropped a shot on the 15th and double-bogeyed the next hole to allow Madsen to take over at the top of the leaderboard.
- Sports & Recreation
- Charl Schwartzel