The Waratahs couldn't take the lead until the 66th minute, however, when their numbers advantage saw winger Reece Robinson tiptoe his way down the left sideline, before finding his opposite winger Rob Horne looming on the inside. Foley's conversion saw the Waratahs push ahead 25-23.
But lazy defence at the ruck then enabled towering Stormers lock Pieter-Steph du Toit to pick the ball up at the base of a ruck and stroll through virtually untouched to regain the lead for the home side in the 73rd minute. With time running out, Waratahs captain Michael Hooper was able to crash over under posts on the pick-and-drive, with Foley's conversion sealing the two-point win.
The Stormers again had a claim to be aggrieved, with the Waratahs appearing to knock the ball on before scoring their match-winning try.
Earlier, Foley put Kurtley Beale through a hole to post the first points of the match, before the Stormers hit back soon after in an already high-paced match with a converted try to no.8 Schalk Berger.
They extended their lead when du Toit scored in the 24th minute to finish off a passage that started with a break he made back on halfway.
The Israel Folau experiment at outside centre continued to reap rewards just before halftime, when he ran a wonderful line between Stormers flyhalf Jean-Luc du Plessis and inside centre Damien de Allende to score from thirty metres out.
After the Waratahs had been bleeding line breaks themselves, going into the sheds only two points down at the break was better than it perhaps could have been.
Immediately after the match, Hooper praised the efforts of his team to stay in the contest at Newlands, despite going long periods through the match with minimal possession.
"It's one of the toughest places to play rugby; a really loud crowd tonight, a fantastic place to play for us, and it was a grind. The Stormers threw a lot at us, their offloading game is really impressive, and we're lucky there to get a win," he told South African broadcasters SuperSport.
"We had to make the most of the opportunities we had [in the first half, with only 30 per cent possession], and we did; our backs were great. And we need that from the guys. We need, when we get the ball, to be able to capitalise, and we did that especially in the first half. And then the forwards got us over at the end."
Hooper was thrilled with the way the Waratahs remained patient to the end, having lost matches in similar positions already this season.
"We've been there a couple of times this year, and come out on the wrong side of it, so it wasn't anything unfamiliar. Getting the win, though, is a step in the right direction, and to do it here, I'm extremely happy for the guys.
"It's going to be nice to fly home with the win to our names."
The Waratahs return to Sydney to host the Cheetahs at Allianz Stadium next Saturday.
-AAP