Sean McCaffrey’s side ended almost five-and-a-half hours of football without a goal when captain Shields headed his side in front on 51 minutes after getting on the end of Dan Cunningham’s free-kick.
They then doubled their advantage just four minutes later when former Bray Wanderers striker O’Neill sent a looping header over goalkeeper Mark McGinley, punishing the students for failing to attack the ball.
A tense finish was set up when Graham Rusk pulled a goal back from the penalty spot on 68 minutes.
However, Dundalk managed to hold out for a deserving win — the first for new boss McCaffrey.
The Louth men were unlucky not to open their account in the first-half with UCD netminder McGinley having to be at his best to finger-tip Stephen McDonnell’s effort on the crossbar on 21 minutes.
With the Lilywhites still reeling from that miss, Martin Russell’s visitors broke at pace with Chris Mulhall being played through on goal only to be denied by a stunning stop from Peter Cherrie.
Both keepers had to make further crucial saves before the break with McGinley turning Michael Rafter’s low drive around the post on 23 minutes before Cherrie was forced into a full stretch save to deny Daniel Ledwith eight minutes before half-time.
However, Dundalk’s long wait for a goal was nearly over.
DUNDALK: Cherrie; McLaughlin (Byrne 72), Foran, Burns, Murphy; McDonnell (Cunningham 46), Mountney, Shields, Walsh; Rafter, O’Neill (Reilly 66).
UCD: McGinley; Ledwith, Kavanagh, D O’Connor, Nangle; Mulhall, P O’Conor, Corry (Douglas 84), McCabe (Langtry 63); Benson (Morrison 63), Rusk.
Referee: Phil Caschera (Dublin).