Simon Weaver’s side fell behind when Matt Paterson converted from the penalty spot on 22 minutes, though Michael Woods’ close-range finish levelled matters shortly before half-time.
The visitors created plenty of chances to win the game after the break, but it took until the 81st minute for them to move ahead, Jack Muldoon hanging up a cross from close to the byline that George Thomson nodded home.
And that goal means that Town now have a five-point cushion between themselves and the other side of the play-off places.
“After four games without picking up a win, three points was vital,” reflected Agnew, who arrived as a first-half substitute for Lloyd Kerry.
“It’s huge. The last four games, did we deserve to win any? I’m not too sure, but today there was only one winner and that’s very pleasing.
“We weren’t at our best first half, so to go in at 1-1 was fortunate, but it encouraged us to go on to the second half where we could have won by six or seven in the end.
“The gaffer’s been emphasising that he wants us to get back to playing, so the three points was massive and to do it in that style was the icing on the cake.
“It looks like results went in our favour but we’ve just got to concentrate on ourselves.
“We’ve got four cup finals. We know what we’ve got to do to get into the play-offs and if we keep that togetherness and team spirit then I can’t see why we can’t get four good results.”