The class and finishing power of Denis Hickie ensured that Belfast Harlequins' relegation worries will continue for the moment.
The international winger scored one try and set up two others as St Mary's turned a 153 interval deficit into a seven-point margin of victory.
Harlequins' confidence soared throughout the first half, never more so than following Andy Park's 28th minute try, which was converted by Paul Hancock, who had earlier opened the score with a penalty. And when Robin Morrow charged in for a try in the 38th minute, Harlequins looked comfortable at 15-0 but Mark McHugh provided a ray of hope for the visitors with a penalty just on the stroke of half-time.
Hickie went in for the Dublin side's first try in the 47th minute to which McHugh added the points.
And even though Harlequins enjoyed a generous ration of possession they found themselves vulnerable to breakaways by St Mary's. Shane Jennings proved the point when going clear for the second try for St Mary's in the 60th minute with McHugh again converting.
Harlequins were caught napping again when Peter McKenna broke clear to grab what proved to be the winning score for St Mary's in the 59th minute.