It was no more than the home side deserved, after a disciplined performance which restricted the visitors to just four shots on target over the space of the 90 minutes.
The home side had just two shots of their own on target, but both efforts found the net to stun the defending champions, and with Cork City winning at home to Bray Wanderers, the Lilywhites are now 12 points off the pace.
The winner came from a United counter-attack on the left, with Kevin Devaney playing the ball inside to David Cawley. His shot was blocked, but Shanahan was racing in to latch onto the rebound, his shot flying past Gary Rogers with the aid of a deflection.
Dundalk had dominated possession in the early stages, without ever threatening Conor Winn’s goal, while United were content to hit them out wide on the counter attack, a ploy which paid off in the 25th minute.
Kevin Devaney led the break before laying the ball off to Ronan Murray, who crossed for the unmarked Faherty to head past Gary Rogers from eight yards.
Jamie McGrath dragged his 32nd minute shot wide as Dundalk searched for the equaliser, but David McMillan had more joy for the visitors four minutes later.
The striker was left unmarked in the penalty box and he had the time to trap Brian Gartland’s pass before turning and smashing a shot past Winn.
Winn; Horgan, Grace, Folan, Ludden; Shanahan, Holohan (Sinnott 90), Cawley, Devaney; Murray (Devers 83); Faherty (Cunningham 86).
Rogers; Vemmelund (Mountney 72), Gartland, Hoare, Massey; Shields, O’Donnell; Duffy, McEleney, McGrath (Kilduff 79); McMillan (Stweart 84).
Ben Connolly (Dublin).