The Robins, who were held to a 1-1 draw in the original second-round game, took the lead when Shaun Harrad converted from the penalty spot in first-half stoppage time.
Sam Clucas levelled for the Blue Square Bet Premier Bulls in the 74th minute but Mohamed booked Cheltenham a lucrative clash against David Moyes' men.
Hereford suffered a damaging blow as early as the 11th minute when leading scorer Ryan Bowman was forced off with a knee knjury.
Otherwise the first-half produced little of note until stoppage time.
Cheltenham keeper Scott Brown made a blinding save to deny Clucas a goal, with the action immediately returning to the other end where Cheltenham took the lead.
Jermaine McGlashan hit the deck under a challenge from Andy Gallinagh and referee Dean Whitestone awarded a soft penalty before Harrad rammed the spot-kick past James Bittner.
Hereford huffed and puffed in the second period but Cheltenham seemed comfortable until the fortuitous equaliser arrived.
Clucas sent in a cross from the left but there appeared to be little danger as the ball dribbled through the area before landing in the corner of the net.
There were few chances as the game progressed through added time before Mohamed struck with seven minutes remaining in extra-time.