After a goalless first half, Chelsea loanee Bamford opened the scoring in the 63rd minute to leave the home fans delighted.
It appeared they would go home happy when Tomlin struck 11 minutes from time, his effort appearing to put the result beyond doubt.
But there looked like a twist in the tale was on the horizon when Kenwyne Jones struck in the 86th minute to set up a tense finale.
It mattered little, however, as Aitor Karanka's men held on the claim a valuable three points.
The Teesside club subsequently rose in the table and now sit just a point behind leaders Bournemouth, albeit with the rest of the chasing pack holding a game in hand.
Boro enjoyed the brighter start, with Kike and Grant Leadbitter going close during the opening exchanges.
The hosts were adamant they should have had a penalty after 16 minutes when Kike went down under a challenge from Cardiff goalkeeper Simon Moore.
The Bluebirds came back into the game as the half worse on, albeit without creating any real clear-cut opportunities.
Indeed, chances were at a premium over the remainder of the half, Bamford coming the closest as his scuffed effort missed the target.
Boro again looked the stronger team after the interval, although Cardiff's Kadeem Harris was unlucky to be denied by a fine Dimi Konstantopoulos save.
And that miss was to prove costly as Boro took the lead soon after, Bamford ending a fine move by firing home.
Middlesbrough calmed noticeably thereafter and almost grabbed a second when Kike nodded just wide from Bamford's superb ball.
The Spaniard continued to threaten, too, and once again was close to finding the net when Moore intervened with the striker bearing down on goal.
Still the home side pressed forward in search of another, with Reach threatening before substitute Albert Adomah cleverly worked an opening and forced Moore into a save.
A couple more chances fell their way until Tomlin finally appeared to settle the nerves.
Another lovely move proved pivotal, with Adam Clayton and Adam Reach paving the way form Tomlin to double the advantage confidently.
Jones then threatened to flip the script with a close-range finish, but Boro held on to secure the points and pile the pressure on leaders Bournemouth.
Cardiff, meanwhile, remain adrift of the play-off places in 13th.