The 26-year-old bagged his third and fourth goals of the season as Huddersfield’s 29-year wait for win on Teesside continued.
Boro wasted a glut of chances before Tomlin drilled home a brilliant effort just after the hour.
Former Boro man Jacob Butterfield forced a great save from Dimi Konstantopoulos, and the Greek goalkeeper twice denied forward Nahki Wells with two late saves.
But as the Terriers pushed for a leveller, throwing goalkeeper Alex Smithies up for a late corner, Boro cleared and enabled Tomlin to make sure of the three points with the last kick of the game.
Boro went agonisingly close to opening the scoring as early as the sixth minute when Kike was inches away from bagging seventh of the season.
The Spanish striker cleverly stepped past Mark Hudson before shooting from the edge of the area, but his effort rebounded back off Smithies’ right-hand post.
Patrick Bamford had a great chance to put Boro ahead in the 10th minute when he brilliantly controlled a ball over the top and rounded Smithies before rolling the ball just wide.
Aitor Karanka’s men continued to press and in the 42nd minute former Huddersfield midfielder Adam Clayton found himself in a great position on the edge of the box but could not get over the ball enough and blazed over the bar.
The Terriers had their first shot at goal deep into first-half injury time when Wells shot from the edge of the area but Ayala managed to get a leg in the way.
Boro started the second half still on top, with chances going begging.
Within a minute of the restart, Bamford did well to wriggle past Hudson on the touchline before pulling back for Kike, but he skewed his shot well wide.
And Tomlin was the next to go close in the 48th minute when he charged forward before blasting over the bar from the edge of the box.
In a rare Huddersfield attack, ex-Boro midfielder Butterfield probed around the edge of the box before unleashing a left-footed effort which flashed well wide.
Boro found the elusive goal just after the hour when Tomlin picked up a loose ball and opened up before hammering home a rocket from 20 yards.
Town almost hit back just two minutes later when Butterfield’s thundering long-range effort was tipped round the post by Konstantopoulos.
The visitors almost levelled in the 78th minute when Wells curled a brilliant left-footed effort beyond Konstantopoulos but it came back off the post.
The Boro keeper denied Wells again twice in the last minute with two fine saves.
It made for a nail-biting finale as the Terriers pressured for a late equaliser, with Tomlin breaking away in the 94th minute before rolling into an empty net with the last kick of the game.