Stock, who has endured injury problems in recent seasons, pounced from 12 yards in the fourth minute of added time - his first goal since March 2009.
Middlesbrough, who have now taken just four points out of a possible 33 on their travels, made a flying start when Scott McDonald put them ahead inside four minutes.
Marvin Emnes set up the Australia striker, who fired into the bottom corner from 12 yards for his third goal in six games.
Doncaster levelled in the 22nd minute through in-form striker James Hayter.
Former Sheffield United forward Billy Sharp delivered the cross and Hayter made no mistake with his header from six yards - his sixth goal in his last eight.
But just when it seemed the sides would have to settle for a draw, Stock popped up with the winner to ensure Doncaster made the perfect response to last Saturday's 5-1 defeat at Leicester and condemned Boro to a ninth away loss this term.
Boro, buoyed by their home win over high-flying Cardiff last week which lifted them out of the relegation zone, made a bright start and David Wheater - back after suspension - headed an early Gary O'Neil corner over the crossbar.
But the visitors took the lead through McDonald moments later with what was only their fifth goal in their 11th game on the road this term - having been blanked seven times so far.
Doncaster tried to respond and Mark Wilson drove a shot over the bar before Hayter did likewise from 20 yards a few minutes later.
However, Hayter was on hand to take advantage of his second opening as he drew Doncaster level from close range after good work by strike-partner Sharp.
Boro nearly began the second half as they started the first but a fine save from veteran Doncaster goalkeeper Neil Sullivan denied Leroy Lita from 18 yards.
Back came Doncaster and Sharp was thwarted by Boro goalkeeper Jason Steele before Stock shot wide from 12 yards.
Sullivan had to be alert again to tip over a Lita shot from 12 yards in the 65th minute.
Moments later the home side nearly went in front but after Joseph Mills saw his shot parried by Steele, he couldn't keep the rebound down and then John Oster cleared the bar from 18 yards as Rovers enjoyed some possession.
Doncaster created another opportunity with 13 minutes left but James Coppinger was foiled by Steele and Oster fired another effort over the bar as the hosts continued to press.
Middlesbrough weathered the storm as came close to going back in front with eight minutes left but Sullivan produced a fine save to tip Tarmo Kink's 20-yard shot around the post.
Steele saved superbly from Dean Shiels in injury time but moments later Stock came up with the winner.