City captain Richard Dunne was amongst a number of Irish players to go close in the first half before Wigan's Kevin Kilbane finally made the breakthrough in the 49th minute.
But the Republic failed to build on their lead and were facing an embarrassing draw when San Marino claimed an 87th-minute equaliser following a mix-up between Dunney and goalkeeper Wayne Henderson (Brighton).
The Republic almost regained the lead through substitute Anthony Stokes (Sunderland), before Ireland clinched the win almost five minutes into added time, the City youngster poking the ball home following a corner.
That was only the Republic's second win in five games in Group D and they were already facing an uphill battle to qualify for Euro 2008 with Germany and the Czech Republic at the top of the group.
England went down 1-0 in a friendly against Spain but Joey Barton replaced Frank Lampard for the last 11 minutes to make his England debut.
Micah Richards also came on in the second half, replacing Gary Neville in the 65th minute to win his second England cap.
On Tuesday, City boss Stuart Pearce took charge of England Under-21s for the first time after accepting the role on a part-time basis.
England's youngsters came from 2-0 down to draw 2-2 against Spain at Derby, with the goals comng from David Nugent (Preston) and ironically Leroy Lita (Reading), who scored twice against City at the weekend.
Pearce, who has taken charge until after this summer's European Championships in Holland, also gave an international debut to Joe Hart.
The 19-year-old City keeper, who is currently on loan at Tranmere, came on as an 81st-minute sub for Scott Carson.