Dagenham and Redbridge virtually sealed Football League safety as Gillingham's play-off hopes were dealt a blow.
After Abu Ogogo's shot has been parried, Brian Woodall was on hand to fire in the Daggers' opener.
Gills keeper Paulo Gazzaniga made a smart save to deny Josh Parker, before the hosts levelled when Rowan Vine found space in the box and curled home.
Substitute Dominic Green broke down the right flank, beat two defenders and fired in from the edge of the box.
The Daggers are now nine points clear of the relegation places with just three games to play.
Meanwhile, Gillingham sit four points behind seventh-placed Oxford.
VIEWS FROM THE DRESSING ROOM
Gillingham manager Andy Hessenthaler told BBC Radio Kent:
"We weren't good enough and all credit to Dagenham as they deserved to win. We had enough of the ball but didn't do enough with it.
"We dropped our heads and got nervous. We got a fantastic goal and I could only see us winning and it's difficult to see we lost the game.
"But, all in all, it was a disappointing game and we were off it today.
"We're still in there, the chairman's come in and said 'get your heads up', but we've got a mountain to climb. We've got to win four our of four and we're making it very difficult for ourselves."