Newport almost took a shock lead in the 14th minute when a long throw into the box was flicked on and Tyreeq Bakinson looked certainly to score, only for Ederson to superbly get across his goal and palm the header away.
Six minutes later City got another scare, again from a long throw, as Joss Labadie fired well wide of the target.
Mahrez then had City's first real sight of goal, but he couldn't get past goalkeeper Joe Day from a tight angle.
Newport then found themselves on the back foot in the 34th minute as Mahrez brought another save out of Day before some neat play put Sane through on goal, but the Germany international could only clip the top of the bar with his effort.
Just before half-time, Mark O'Brien was lucky to escape a penalty shout when he appeared to block Sane's effort with a raised arm, then Danilo tried his luck from distance but it was always curling wide of the post.
City did break the deadlock six minutes after half-time when Gabriel Jesus fed in Sane, whose shot hit Day in the face and looped over the goalkeeper into the empty net.
The goal deflated Newport and City were in complete control, Day making a great save to push Danilo's effort onto the post from an angle.
Despite being forced to chase the ball around for large periods of the second half, O'Brien had a chance to level in the 73rd minute but could only head into the hands of Ederson.
But two minutes later the game was over as Foden collected the ball in his own half, skipped forward and fired a shot through Day, who should have done better.
Sane almost had his second but Day saved from point-blank range, and Jesus saw a shot from the edge of the area easily held.
It looked like there could be a grandstand finish when a defensive error by substitute Aymeric Laporte and Nicolas Otamendi allowed Padraig Amond to keep up his second of scoring in every round of the FA Cup this season.
But 71 seconds later Foden fired home his second to make the tie safe once again, and Mahrez got himself on the scoresheet from John Stones' pass in the final minute of stoppage time.