Foley booted four penalty goals in the second half to finish with 19 points and prove the difference as the Reds outscored the Waratahs four tries to two.
The Reds tried desperately to grab a draw with a closing passage of 27 phases before Will Skelton dived on a loose ball and the ball was kicked out after the fulltime siren to see out the win.
It was the Waratahs' seventh consecutive derby win over the Reds, who have now lost 10 derbies against Australian opponents and seven of their last eight games this season.
It was a turnaround for the Waratahs, who crashed to an ignominous 26-24 loss to South African strugglers Southern Kings in Sydney last week.
"It was a massive contest, the crowd was into the game and it was great for rugby to still have such great rivalry in sport," Waratahs skipper Michael Hooper said.
"I am really proud of the guys for putting in that effort off a couple of tough weeks."
The win was crucial for the Waratahs as they aim to overhaul Australian conference leaders the ACT Brumbies while the Reds slumped to 2-7.
Queensland's poor discipline cost them dearly in conceding 16 penalties to give the Waratahs their chance.
"It's disappointing. We wanted to come out and do the Queensland fans proud, but we made too many silly mistakes and our ill-discipline piggy-backed them," Reds skipper Samu Kerevi said.
Back-to-back tries from Lukhan Tui and Izaia Perese put Queensland 12 points ahead in the 32nd minute.
But Wallaby flanker Hooper scored a try just before half-time for the Waratahs to trail 19-17 at the interval.
Perese was yellow-carded from the kick-off to the second half for taking out an airborne Dean Mumm.
Foley landed a penalty while he was off the field but the Reds struck back just as Perese returned through Stephen Moore, who scored off the back of a rolling maul for his first try since returning to the Reds.
Foley closed it out for the Waratahs with his three penalty goals.