For 70 minutes Rochdale ran Oxford ragged but they had only a goal by Michael Oliver in the 44th minute to show for it.
Oliver's left-foot drive from the edge of the penalty area went into the top corner of the net with goalkeeper Andy Woodman miles away.
But it all changed when a fluke goal in the 72nd minute by Dave Savage brought the visitors level.
Savage's shot-cum-cross went over the head of goalkeeper Neil Edwards who was injured and unable to make a simple save.
It was anybody's game after this with substitute goalkeeper Matthew Gilks making a superb save from Jefferson Louis.
Newly signed Gavin Melaugh headed Rochdaleâ€™s winner with three minutes left when he got on the end of Clive Plattâ€™s cross.
Melaugh's header sealed a vital win for Rochdale who, although still in the FA Cup, remain just above the relegation dogfight.
Oxford had very little to offer for much of the match but they did turn on the heat late on and Rochdale must have wondered if they were going to throw all three points away.
Rochdale stuck to their guns through the hard part - the last 15 minutes or so - with defenders Gareth Griffiths and Simon Grand both doing well to stem the tide of hopeful raids by increasingly optimistic Oxford.
Early on Rochdale had plenty of chances to make the game safe but despite all their opportunities they did not give goalkeeper Andy Woodman a lot to worry about before Oliver produced his ace.
Rochdale well deserved to win and Oxford - despite their high league position â€“ did not begin to produce the goods until late on.