Mary's looked set to retain the Dr Michael Smyth Memorial Trophy, which is fought for between the two Dublin clubs, as captain Barry Lynn added two penalties to lock Gareth Logan's first half try.
The visitors led 8-3 at the break, with Robbie McCarthy kicking a penalty for the hosts.
However, second half tries from number eight Dunlop and Gallagher saw 'Nure triumph to finish ninth in the final Division One table, a point ahead of neighbours Mary's.
Scorers -
Terenure: Tries: Alex Dunlop, Kevin Gallagher; Con: Mark O'Neill; Pen: Robbie McCarthy. St Mary's: Try: Gareth Logan; Pens: Barry Lynn 2.
HT: Terenure College 3-8 St Mary's College.
Garryowen 50-7 Galwegians
Garryowen ran amok at Dooradoyle, posting a seven-try win, to beat off rivals Shannon for a place in the AIB All-Ireland League Division One semi-finals.
All three top flight sides from the city finished on 48 points, but the better scoring differences of Garryowen (+122) and UL Bohemians (+119) have seen champions Shannon (+117) run out of contention.
Already assured of their top flight status, Galwegians trailed by 31-0 at the break.
Garryowen's tries came from Anthony Kavanagh (2), Conan Doyle (2), Mark Melbourne, Ciaran O'Boyle and Cillian O'Boyle, with Eoghan Hickey kicking 15 points.
Nick Wakley grabbed Galwegians' only try before adding the conversion.
Scorers:
Garryowen: Tries: A Kavanagh (2), C Doyle (2), M Melbourne, C O'Boyle, C O'Boyle; Cons: E Hickey (6); Pen: E Hickey. Galwegians: Try: Nick Wakley; Con: N Wakley.
Blackrock College 12-10 UL Bohemians
UL Bohemians squeezed into the AIB All-Ireland League Division One semi-finals despite losing to Blackrock College this afternoon at Stradbrook.
Incredibly, all three Limerick clubs in the top flight finished on 48 points on the last day of the season, with a better scoring difference seeing Bohs claim fourth spot.
First half tries from flanker John Ed O'Connor and scrum-half Fergal Lawler saw Bohs fight back to trail 12-10 at the break.
Number eight Paul Graham and hooker Cian Culleton crossed for 'Rock's opening tries.
The Dubliners swept to victory with further efforts from player coach Emmett Farrell and man-of-the-match Fionn Carr.
Cork Constitution made it eight AIB All-Ireland League Division One wins on the trot to end the regulation phase of the season on a high at Temple Hill.
Having already booked a home semi-final, table toppers Con played second fiddle for much of this encounter, which saw Ballymena lead 5-3 at half-time.
But Brian Walsh's Leesiders upped the gears and tries from winger Cronan Healy and prop Timmy Ryan saw the hosts keep up their winning run ahead of next weekend's play-off against UL Bohemians.
Relegation-threatened Ballymena grabbed a much-needed bonus point thanks to tries from full-back Chris Smyth (2) and lock Ian Caldwell.
Scorers:
Cork Con: Tries: C Healy, T Ryan; Con: R Lane; Pens: R Lane (3); Drop: D Lyons. Ballymena: Tries: C Smyth (2), I Caldwell; Con: C Woods.
HT: Cork Con 3-5 Ballymena.
Clontarf 43-0 Dungannon
Clontarf cruised into the Division One semi-finals for the fifth time in the past six seasons with a bonus point win at Castle Avenue.
Clontarf dismantled Dungannon to post up a six-try victory, which earns them a home semi-final against Garryowen, a team they lost to -12-10 - two weeks ago.
Needing a big win to guarantee a second-place finish, the Dubliners ran riot in the second half, having led 15-0 at the interval.
Full-back Conal Keane, centres Daragh O'Shea and Max Rantz McDonald (2) and half-backs Fiach O'Loughlin and Niall McNamara shared out 'Tarf's tries with Keane kicking 13 points.
Scorers:
Clontarf: Tries: C Keane, D O'Shea, M Rantz-McDonald (2), F O'Loughlin, N McNamara; Cons: C Keane (5); Pen: C Keane.
After five straight seasons in AIB All-Ireland League Division One, Belfast Harlequins have been relegated as UCD edged this do-or-die duel at Belfield.
Needing a win to survive in the top flight, centre Fergus McFadden came up trumps for the Students by nailing a 74th-minute penalty.
It has been a week to forget for 'Quins as they also lost the AIB Cup final last Saturday.
Darren Cave landed a first half penalty to put 'Quins 3-0 in front at the break. But McFadden soon levelled and also angled over the match winner.
Scorers:
UCD: Pens: F McFadden (2). Belfast Harlequins: Pen: D Cave.