Victory saw the Rams move level on eight points with third-bottom Swinton Lions in their fight against relegation from the Kingstone Press Championship, although they left it late to snatch a fourth league win of the season.
Oldham struck first after three minutes as Scott Leatherbarrow sent Danny Grimshaw crashing over and Leatherbarrow converted.
Dewsbury fought back to level through Dale Morton’s 16th minute try wide out, which Paul Sykes converted from the touchline.
However, Oldham regained the lead when Michael Ward forced his way over and Leatherbarrow converted as the home side led 12-6 at half-time.
Oldham had Adam Neal sin-binned for an off the ball challenge and Dewsbury took advantage just two minutes later when Gareth Moore’s kick rebounded off a defender and Aaron Ollett gathered to score, with Sykes converting to level.
Oldham edged ahead with a Leatherbarrow penalty and the half-back landed another goal to give Oldham a 16-12 lead late in the game.
In a dramatic finale, Moore charged down an Oldham kick and regathered the ball to score behind the posts and Sykes slotted over the goal to edge the Rams ahead for the first time.
When Oldham were penalised in the final minute, Sykes slotted over the goal as the hooter sounded to seal a dramatic Dewsbury win.