Steven Caulker put the Bluebirds ahead with a header but Bryan Ruiz equalised on the stroke of half time for the hosts.
It looked to be heading for a draw but substitute Jordon Mutch sealed the three points with an injury-time wonder strike.
The win came after a last-gasp loss to Spurs in the league last Sunday and 3-2 Capital One Cup defeat at West Ham in midweek.
Mackay admitted he thought the game at Craven Cottage would end as a draw and he was delighted both with the win, and the performance of his players.
He told Sky Sports: "I thought we were fantastic today, from the first minute. I think we ended up with 24 shots at their goal today.
"But they showed real resilience. We've had a tough week, we've had two long away trips this week but we kept going until the end.
"We put three substitutions on to go and try and win the game and one of them actually ended up scoring.
"So just reward in the end I think.
"It was a fantastic strike from him (Mutch). He's a top young player but overall I thought it was a really good performance."
Mackay was delighted his side had the belief to go out and win following the late loss to Spurs last week.
"I thought we were excellent last week against Spurs," he added, "and it was a cruel blow to lose in the last minute or so but we thoroughly deserved the three points today."