LUKE BECKETT delivered a deadly double as 10-man Town left Rotherham staring relegation in the face.
The frontman struck after just two-and-a-half minutes, then doubled his tally 45 seconds into the second half.
His 10th goal of the season gave Town a 2-1 lead, a situation which seemed unlikely after right-back Andy Holdsworth was shown a straight red card on 28 minutes for deliberate handball, and Chris O'Grady fired home the resultant spot kick to equalise.
Rotherham pounded the Town goal after their penalty lifeline, but Peter Jackson's side stood firm, and after Beckett had put them back in front, stretched their lead with a well-worked 58th-minute goal from midfielder Michael Collins.
Town old boy Delroy Facey pulled one back on 70 minutes, but the visitors deservedly held out through five minutes of added time as Rotherham also finished a man down after the 86th-minute sending off of Ian Henderson for a second yellow.
Jackson had demanded a win to keep alive Town's play-off hopes, but the three points were also needed to keep his side clear of the wrong end of a League I table propped up by Rotherham, who are now 12 points adrift of safety.
Although robbed of the services of striker Andy Booth, who missed his first match in 19 with a calf strain picked up on the training ground, Town made the perfect start.
Chris Brandon, who stepped in for Booth, robbed Craig Fleming on the edge of the box, made for the goalline and squared the ball for Beckett to check and shoot home.
And the lead could have been increased on 20 minutes when Danny Schofield, playing wide left, had a shot pawed away by goalkeeper Gary Montgomery.
Rotherham's best efforts had been an early Martin Woods shot which Matt Glennon acrobatically palmed over and an O'Grady drive which was cleared up by left-back Andy Taylor after Glennon blocked with his legs.
But Glennon couldn't keep out O'Grady's well-struck penalty after Holdsworth had been ruled by referee Eddie Ilderton to have blocked centre-back Ian Sharps' shot with his hands (the Town player insisted the ball hit his face).
Rotherham upped the tempo, and centre-back David Mirfin came to Town's rescue with a well-timed challenge as Henderson shaped to shoot after Glennon could only block an O'Grady shot.
Then Henderson had Glennon stretching to tip a shot over the bar.
Whatever Jackson said at half-time worked because Town bossed the early stages of the second half.
Beckett rose to head home as Brandon crossed after linking neatly with Gary Taylor-Fletcher, who was operating on the right of midfield.
Then, after a cross from central midfielder Matty Young was cleared, Taylor-Fletcher broke and fed Collins, who finished with a low right-foot shot.
The thousand or so Town fans behind the goal were almost celebrating again when Mirfin headed goalwards from Schofield's cross, only for Montgomery to save.
Collins then had another shot blocked before, with Young off the field for treatment, Facey headed home after a flick-on by Henderson.
Rotherham, however, could muster only two more clear chances, a chip by Facey which was held by Glennon and a close-range Henderson shot which the keeper smothered.
Luke Beckett's second goal, headed home from Chris Brandon's cross just 45 seconds into the second half. Having finished the first half in the ascendancy and with a numerical advantage, Rotherham must have been planning to come out and turn the screw on Town, but they never hit full throttle.
How They Rated
Matt Glennon Couldn't be blamed for either Rotherham goal and came to his side's rescue several times. Booked for time-wasting. Rating: 7/10
Andy Holdsworth Had started strongly and swore blind Ian Sharps' shot hit him in the face, not the hands. The referee thought otherwise. Rating: 6/10
Andy Taylor Made a key goalline clearance and got through a lot of hard work defensively as Town took the points. Rating: 7/10
Frank Sinclair Grateful to Glennon for saving after a miscued header back but otherwise, a third very solid performance. Rating: 7/10
David Mirfin Cool and collected, used his physical strength well and continues to link neatly with Sinclair. Rating: 8/10
Gary T-Fletcher Got through a huge amount of running, made some telling challenges and had a hand in two goals. Rating: 7/10
Michael Collins Did a lot of the nuts and bolts work in midfield and chipped in with a well-struck second goal of the season. Rating: 7/10
Matt Young Seemed to pop up all over the place and made himself a problem for the home side with his tackling and passing. Rating: 7/10
Danny Schofield Town's flair player was also prepared to roll up his sleeves and get stuck in to help the victory effort. Rating: 6/10
Chris Brandon Made a great effort at filling in for injured Andy Booth up front. Worked very hard and made both Beckett's goals. Rating: 7/10
Luke Beckett His double was central to the success, but the striker also performed his defensive duties with enthusiasm. Rating: 8/10
Spotlight on the Ref
Town were unhappy with the sending off of Andy Holdsworth, but Tyne and Wear whistler Eddie Ilderton was well placed to rule handball, and having given the penalty, the red card was sure to follow. Not much debate about Ian Henderson's dismissal or cautions for Town trio Glennon, Taylor-Fletcher and Collins.
Montgomery, Worrell (Facey, 66mins), Fleming, Sharps, Brogan, Partridge, Cochrane, Bopp, Woods, O'Grady, Henderson. Subs not used: Liversidge, Streete, Newsham, Mills. Sent off: Henderson (second booking, 86mins).