League One high-flyers City put in a fine display at Ashton Gate and striker Matt Smith saw two headers cleared off the goalline during a dominant first-half performance from the hosts.
However, substitute Diafra Sakho's back-post header in the 81st minute was enough for West Ham to move through to the fifth round and avoid the same fate as the likes of Chelsea and Manchester City, who fell to Bradford City and Middlesbrough respectively on Saturday.
"I knew it was going to be a tough game and it was exactly that," Allardyce told BBC Sport.
"Bristol City showed why they are where they are in the league with their form.
"We found it difficult to get our passing routine going but when the one chance popped up it was all we needed to get a very important victory.
"Bearing in mind what has happened this weekend, it is a big result for us."
Centre-back Winston Reid concedes that West Ham failed to meet expectations in the first half, but felt the Premier League side were rewarded for remaining patient.
"In the first half we were under pressure," he added. "It is always difficult coming to these places. Bristol City put in a good performance but we put in a clean sheet and Diafro Sakho got the goal, so it was good.
"We wanted to come here and finish off the game and we did, even though we had to wait for that.
"The manager spoke before about the upsets yesterday, and we did not want to be one of them."
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.