Substitute Mark Timlin kept St Pat's revival on the boil with a free-kick winner at City Calling Stadium.
Unbeaten in four games, Liam Buckley's Dubliners move back into the top half of the table.
The result was harsh on managerless bottom side Longford, who had the better of the first half, finally springing a dour game to life on 33 minutes.
Goalkeeper Paul Skinner's long free-kick was flicked on by Eddie Dsane for Kaleem Simon, whose angled volley came back off the far post.
Maintaining the upper hand, home defender Noel Haverty put a free header wide from Guais Makouta's free-kick on 41 minutes.
Pat's finally threatened in the minutes before the interval, with Stephen Kinsella just failing to meet an inviting Conan Byrne cross at the back post.
Central defender Rory Feely then wandered up for a Byrne free-kick only to plant his header wide.
The visitors upped their tempo in the second half, earning their first corner of the game on 57 minutes with Byrne's ball into the area met by Michael Barker, whose shot was blocked.
A minute later, Town defender Jamie Mulhall bravely blocked a drive from Lee Desmond.
Timlin then won it for St Pat's on 73 minutes. Haverty's foul on Jamie McGrath was clinically punished when the Donegal native curled the ball up and over the defensive wall to the net.
Longford Town - Skinner; J Mulhall (Gorman 90), Haverty, Mvita, Powell; Cowan, Gannon, O'Connor, Makouta (DIllon 80); Simon, Dsane.
St Patrick's Athletic - O'Malley; Barker, Hoare, Feely (D Dennehy 68), Bermingham; Kelly, Desmond; Byrne, McGrath, Kinsella (Timlin 64); Fagan (Corcoran 88).
Ref - B Hennessy (Clare).