After Humphreys kicked his side into an early 12-0 lead, Foley's men scored 21 unanswered points through tries from Robin Copeland and Duncan Williams, as well as the boot of Ian Keatley.
A missed penalty from Keatley and a yellow card for Stephen Archer then handed the initiative back to the visitors, with Nick Williams going over in the 79th minute only for Humphreys to push his attempt agonisingly wide.
And though Foley afforded himself a rueful grin after the result took Munster above their opponents in the GUINNESS PRO12 table, he has warned his players that they will not always be so fortunate.
"The first 20 minutes was all them and we were giving away penalties that we knew the referee was going to be hot on. That was very frustrating in itself," Foley said.
"Then we executed a nice little play and managed to get momentum into the game and from there we took it, right up into the 60th minute.
"We were nine points up in perfect control of the game and opt to go for the posts instead of going to the corner and keeping the pressure on Ulster.
"It hits the post and they go down the other end. We get a man put in the sin bin and then they get three points and suddenly we're hanging on for dear life at the end.
"And it was down to a missed conversion we won the game. That isn't the ideal way of winning but you take it and run away, and you have a little smile on your face."
Click here to view the best images from Munster's dramatic triumph over Ulster
Follow us on Facebook, join the conversation on Twitter, sign up to our YouTube channel for extensive match highlights and sign up for our newsletter for regular updates on the GUINNESS PRO12
Guinness PRO12
Suite 208, Alexandra House,
The Sweepstakes
Ballsbridge, Dublin 4, Ireland