Teenage sensation Conor Murphy was the hero at the Carlisle Grounds, where his brace, the second coming in the 90th minute, sank UCD.
The Students made a bright start but it was Bray who went ahead on eight minutes when Dane Massey played a one-two with Jake Kelly before crossing for Murphy to finish.
The visitors were back on level terms on 20 minutes when Dean Marshall slotted a penalty into the bottom corner, via Matt Gregg's fingertips after Gary Dempsey had fouled the UCD midfielder.
A mistake by Gregg, as he attempted to pick up the ball inside the box, presented Samir Belhout with an opportunity on 24 minutes, but Adam Mitchell cleared his shot off the line.
Graham Rusk and Belhout spurned chances for UCD before the break.
Goalkeeper Ger Barron kept UCD in the game with many fine saves in the second half before Murphy finished from a tight angle on the right in the final minute following an excellent through ball by substitute Daire Doyle.
Bray Wanderers -- Gregg; S O'Connor, Mitchell, Prendergast, Massey (Kendrick 66); Zambra, Dempsey, D O'Connor (Doyle 45), Kelly; Murphy, O'Neill (McGuinness 73).
UCD -- Barron; O'Conor, O'Connor, Colton, Russell (Kavanagh 82); Marshall, Meenan, Corry, Ledwith, Rusk (Nangle 51); Belhout (Doyle 64).
REF -- P Tuite (Dublin).