A cracking free-kick from substitute Mark Timlin kept St Patrick's Athletic's revival going at the City Calling Stadium.
While Liam Buckley's Inchicore side are unbeaten now in four games and have moved back up into the top half of the table, the result was harsh on managerless bottom side Longford, who were the better team in the first half.
Caretaker manager Gary Cronin made three changes to the Longford side that lost 2-0 in Wexford on Friday, Tony Cousins' last match in charge prior to his resignation on Saturday.
Paul Skinner came into goal for the suspended Ryan Coulter while Kevin O'Connor returned in midfield alongside recent signing Gaius Makouta, who made his first start.
In two changes in the St Pat's team from their win over Galway United on Friday, Conor O'Malley came into goal while Graham Kelly started in midfield as Brendan Clarke and club skipper Ger O'Brien moved to the bench.
Longford, keen to redeem their poor display at Ferrycarrig Park, started encouragingly with Don Cowan's pace and tenacity a threat on the right flank.
But it wasn't until the 33rd minute that the home side sprung a dour game to life.
Makouta flicked on Skinner's free kick which dropped for Kaleem Simon whose angled volley came back off the far post.
Longford maintained the upper-hand with Noel Haverty directing a free header wide at the near post from Makouta's free kick in from the left.
St Pat's finally came alive in the minutes before the break. First, Stephen Kinsella just failed to meet an inviting Conan Byrne cross at the back post.
Central defender Rory Feely then wandered up for a Byrne free kick right on 45 minutes only to plant his header wide.
Simon did have the ball in the St Pat's net in first half stoppage time, but the flag was already up for offside.
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 got his body in the way to bravely block a stinging drive from Lee Desmond.
Christy Fagan finally sparked for St Pat's, firing a dipping volley not far over the top on 68 minutes after Barker picked him out with a looping cross.
Minutes later, Fagan turned well some 25 yards out to again shoot over Skinner's crossbar.
Timlin, introduced nine minutes earlier, then won it for St Pat's on 73 minutes as Haverty's foul on Jamie McGrath was clinically punished. The Donegal native curled the ball up and over the defensive wall to the net .
He should then have doubled St Pat's winning margin five minutes from time.
Set up from Graham Kelly's pull-back, Timlin drove wide from just eight yards.