Substitute Dennis Oli's late header gave Gillingham a vital win in their push for automatic promotion.
The Gills now move to within four points of second position, after battling durably to overcome a dangerous Daggers side.
In a furious opening quarter-of-an-hour, with both sides throwing themselves into every challenge, it was the Gills whose pace and quality paid off first.
Big Mark McCammon and the lethally quick Simeon Jackson worked the ball well on the right, winning two corners in the first five minutes.
A cross from McCammon was hastily cleared straight to John Nutter who, beating one man, rifled in a shot that Tony Roberts parried to McCammon who couldn't miss with his volley on eight minutes.
Paul Benson then missed a gaping open goal for the Daggers as Gillingham keeper Simon Royce was left scrambling to clear after a feeble back-pass from his captain Barry Fuller.
Royce cleared the ball straight at Benson, who'll be kicking himself for not levelling the score for his side, volleying wide of the far post.
But the away side's focus worked some clever moves and their equaliser came after some excellent work on the left from Ben Strevens. He whipped a low cross in behind the defenders and, with Royce too slow to react, Sam Saunders tapped home at the far post, just before half-time.
The second half maintained a steady pace with neither side managing to mirror their first-half creativity.
Dagenham were left to rue wasteful balls in the final third, as Gillingham won the game in the 88th minute.
Jackson's trickery won a free-kick in a dangerous area, right of the Daggers box. Nutter crossed with pace and Oli wheeled away in delight, leaving his glancing header nestled in the bottom-left corner.