Declan Foley's injury-time goal gave Derry a hard-earned victory and put a massive dent in Westmeath's title hopes.
The Na Magha forward, not long on the pitch as a late substitute, got his hurl to Kevin Hinphey's dropping shot ahead of Peter Collins to snatch victory for Tom McLean's men.
It looked as though Westmeath had it won five minutes from time, when Alan Devine kicked home on the goal-line after Barry Robinson had stopped the first effort in a scramble.
That put the visitors 3-10 to 1-13 ahead, and Michael Ryan's side looked to be the team with the legs in them to finish it out.
Derry had led by 1-9 to 1-6 at the interval, and were good value for it, though Westmeath weren't aided by hitting 10 wides. Brendan Murtagh was off-colour on the frees and Alan Grant's goal for Derry cancelled out Niall Dowdall's 21st minute major.
The hosts hit the first two scores on the restart but were reined in when Dowdall got above Robinson to flick home a second goal.
Westmeath dominated the next 20 minutes but Derry's workrate kept them in it long enough to steal it at the death.
The victory, on top of earning a point in Kerry last weekend, leaves Derry looking towards the top of the table rather than worrying about the bottom as many suspected they would be.