FA Cup: Bristol City 0 West Ham 1
The Premier League side were well below their best at Ashton Gate, but Sakho stepped off the bench to nod home at the back post in the 81st minute.
Defeat was harsh on League One high-flyers City, who belied their underdog status to dominate the opening period.
Matt Smith was a particular threat and he twice saw headers cleared off the goalline.
West Ham improved after the break, though, and Sakho hit the crossbar before his decisive strike.
That meant Sam Allardyce's side avoided the same fate as Chelsea and Manchester City - eliminated by Bradford City and Middlesbrough respectively on Saturday.
City started on the front and Smith was at the centre of the first clear opening in the sixth minute when a Luke Freeman corner caused chaos in the penalty area and led to the Fulham loanee's looping header being cleared off the line by Mark Noble.
West Ham continued to struggle against a dynamic City attack led by the lively Freeman and Jay Emmanuel-Thomas.
Emmanuel-Thomas combined with Joe Bryan to carve open the West Ham defence soon afterwards, in a move that led to the latter flashing an effort across the face of goal from a tight angle.
City's pressure was relentless and another looping Smith header was denied on the goalline, this time striker Andy Carroll doing his defensive duties with a headed clearance, although there were suspicions of handball against the former Liverpool man.
West Ham were being limited to shots from distance, but Carroll will feel he could have done better with a tame volley from Carl Jenkinson's cross that failed to trouble City goalkeeper Frank Fielding in the 38th minute.
The tempo dropped in the second half, leading Allardyce to haul off Alex Song and Enner Valencia in the 57th minute to be replaced by Morgan Amalfitano and Sakho.
West Ham's ball retention improved, but chances remained at a premium, with Stewart Downing firing an edge-of-the-box shot over the crossbar.
At the other end, City continued to probe and Smith spurned a good chance with 20 minutes remaining when he headed Mark Little's accurate delivery over the crossbar from near the penalty spot.
City were handed a reprieve soon afterwards when Sakho showed expert skill to cut in from the left and unleashed a fierce half-volley that skimmed the crossbar.
However, with nine minutes remaining the same player had the decisive say when he stretched to meet Carroll's cross and headed into the roof of the net.