Derry and Cork stay level on 66 points but the Leesiders have a superior goal difference and a game in hand. UCD, with just one win in their last nine league games, stay in the relegation zone with just three matches left.
Knowing fellow contenders Cork City had recorded a 2-1 victory over Bohemians at Dalymount Park earlier, Derry began in determined fashion and were in front after 13 minutes.
Mark Farren cut in from the left and supplied a superb ball to fellow striker O'Flynn, who cut past defenders Alan Mahon and Tony McDonnell to fire home from eight yards past 'keeper Darren Quigley.
College went close to an equaliser on 25 minutes when scrappy defensive play by Peter Hutton and Clive Delaney almost let in Brian Gannon, only for Derry 'keeper David Forde to grab the winger's stab shot effort.
Former Shamrock Rovers man Paddy McCourt was introduced for winger Killian Brennan on 36 minutes the latter having suffered an ankle injury earlier in the game.
The Students should have been level just before the interval, when a long ball from Mahon was missed by the normally reliable Peter Hutton. Striker Pat Walter, with only Forde to beat, shot against the crossbar from 12 yards.
From the rebound UCD midfielder Mick O'Donnell was fouled outside the box, but Stephen Hurley fired over the bar from the free.
The paltry attendance of just 500 most from Derry had little to enthuse about in the second half.
The visitors almost stretched their lead on 67 minutes when a McCourt free from 22 yards was deflected wide of the target.
Farren should have wrapped up victory for Derry when unmarked he headed inches wide after substitute Molloy found Gareth McGlynn on the right. But his inch perfect cross was squandered by the diving Farren.
Even substitutes Willie Doyle, Ciaran Harte and Conor Sammon could not spark UCD to life.
Molloy at last made the three points safe for Derry in added time when he shot home from 10 yards.
UCD: Quigley; Mahon, McDonnell, Shorthall, Kenna; Gannon (Sammon 84), Dicker, Hurley (Harte 53), O'Donnell; Dupuy (Doyle 45), McWalter.
DERRY CITY: Forde; McCalliog, Delaney, Hutton, Hargan; McGlynn, Martyn, Deery (Molloy 45), Brennan (McCourt 36); Farren (Murphy 90), O'Flynn.
Referee: Declan Hanney (Dublin).