The result of the key four-pointer was in doubt until the closing stages during which time stand-off Jordan Howden dropped a goal and kicked a penalty.
It was a game of two halves with Keighley dominating much of the first 40 minutes and unlucky not to be much further ahead than 14-12 at the break, while the Dons controlled most of the action after the break.
The Dons looked to be suffering a hangover from the defeat at Oldham in the first quarter as the visitors, who were seeking a fourth successive league win, made the early running.
Keighley’s early pressure paid off on six minutes when prop Matthew Bailey finished well to touch down near enough for former Newcastle stand-off Benn Hardcastle to convert.
Sheffield Wednesday's crucial Lee Gregory update as new signing is ruled out 'for some time'
Sheffield Wednesday injury update on Michael Smith, concerns cooled over defensive pair
Who is Luke Cook? Sheffield Wednesday new signing who made debut v Sunderland
“Duracell bunny” “Could’ve done a crossword” – Player ratings as Sheffield Wednesday cruise to win over Sunderland
"They sat behind the ball" - Sunderland boss talks Sheffield Wednesday tactics after Owls win in Carabao Cup
Leading scorer Jason Tali was held inches short following Doncaster’s best chance in the first quarter – much of it spent in their own half - prior to Hardcastle pulling a simple penalty wide on 20 minutes.
He made amends when hitting the target from an identical position three minutes later to give his side an 8-0 lead.
Brad Nicholson, one of three ex-Doncaster players in the Keighley ranks, piled the pressure on his former club when driving over from close range for a 26th minute try converted by Hardcastle, within 90 seconds of coming off the bench.
The Dons were badly in need of some inspiration at that stage and Jordie Hedges, on a rare outing at scrum-half, supplied it on the half-hour when breaking strongly 40 metres out and running on before putting winger Jack Sanderson over in the corner.
Hedges, who had not kicked a goal all season, converted from touch to cut the deficit to eight points.
The visitors returned to the attack and went close to a third try in the 33rd minute before the Dons made further inroads into their advantage with ex-Keighley second-rower Charlie Martin touching down following a good move on the stroke of half-time.
Hedges again added the extras before levelling the scores with a 45th minute penalty.
The home side started the second better than they had in the first and got their noses in front for the first time on 50 minutes when winger Sam Doherty out-jumped his opposite number to collect a Howden kick to the corner. Hedges’ conversion made it 20-14.
The Dons stretched their lead on 56 minutes when hooker Kieran Cross touched down under the posts for another converted try after backing up a strong break by prop Russ Spiers inside the Keighley 20.
Keighley centre Adam Ryder touched down for a converted try on 66 minutes to give his side fresh heart but Howden’s boot ensured they would leave on the losing end.