It looked as if David Wagner’s team would have to make do with a point at basement side Rotherham United, where they had to twice come from behind.
But two minutes into the four added on, skipper Smith popped up to drill in his third goal of the campaign and spark Valentine’s night delight for the Town fans behind that goal.
Town made five changes as they targeted a first competitive win at the AESSEAL New York Stadium, their previous two visits having ended in stalemate, 2-2 in 2014/15 and 1-1 last season.
Tommy Smith returned in place of Martin Cranie at right-back and took the captain’s armband while Tareiq Holmes-Dennis went in at left-back, with Chris Lowe rested because of a hamstring niggle.
Philip Billing was the midfield replacement for Jonathan Hogg, out for up to three weeks with a groin problem, while Rajiv van La Parra dropped to the bench with Joe Lolley earning a first league start since playing at Aston Villa in August, when he picked up a foot injury.
Town went into action with boss David Wagner warning of a direct and physical approach from the hosts, who had claimed all but one of their 17 points going into the contest on home territory.
Rotherham had to clear an early corner as Town took the initiative from the kick-off, but it wasn’t long before the hosts were swinging in a free-kick, with neither Richard Wood nor Tom Adeyemi able to get a connection.
Billing and midfield partner Aaron Mooy were battling away as Town sought to stamp some authority on proceedings, however having spent a spell defending, it was the Millers who struck after 11 minutes.
A counter-attack ended with Adeyemi earning a corner with a deflected shot, and from the flag kick, Ajayi bundled the ball home from close range after a touch from Wood.
Town keeper Ward gathered Joe Newell’s free-kick before Rotherham had the ball in the net again through Jerry Yates, only for Ajayi to be pulled up for offside.
But the visitors were patiently probing, and both Holmes-Dennis and Elias Kachunga had crosses cleared before Lolley’s 19th-minute leveller, the forward netting with a well-placed shot from the edge of the area.
Back came Rotherham, and Ward did well to tip over an awkward cross by left-back Ben Purrington while Newell had a shot blocked before Wood was just too high with a powerful header from another corner.
Billing had a go from distance in the 28th minute, but his effort from Lolley’s pass fizzed over, then Mooy fired in a low drive which home keeper Richard O’Donnell stooped to gather.
O’Donnell had also been tested by Izzy Brown, the on-loan Chelsea forward who spent the first half of this season at Rotherham, and the 20-year-old was denied again after 37 minutes, when his close-range effort after a determined run and cross from Kachunga was deflected for a corner.
Kachunga was looking lively, and when he took aim after a neat Billing pass on 40 minutes, O’Donnell could only push the ball clear rather than keep hold of it.
It was Rotherham doing the bulk of the defending as the first half drew to a close, but Town were unable to get through, with both Holmes-Dennis and Brown thwarted.
O’Donnell needed two attempts to gather Lolley’s shot early in the second half, then Kachunga headed over from Brown’s delivery before, at the other end, Ben Purrington’s shot was held by Ward while Jon Taylor was too high with a 20-yard free-kick.
Town made two changes after 62 minutes, when Van La Parra and Wells replaced Lolley and Quaner, before Kachunga headed Smith’s inviting cross wide, much to the frustration of the 2,583 travelling fans behind that goal.
Billing came close with a header from Mooy’s corner, but the home side regained the lead after 71 minutes, when Adeyemi beat Ward from 25 yards, the keeper getting his hands to the ball but failing to keep it out.
The lead lasted only five minutes before Kachunga squared things up again by heading home his 11th goal of the season from Mooy’s corner.
It looked like heading for a draw, but then Smith produced that wonderful finale.
Bring on Manchester City!