But Sharps struck in a goalmouth scramble after Reuben Reid's free-kick had the visitors in trouble.
In a grim first half the best Dagenham could manage were a string of lame efforts that did little to warm up home keeper David Stockdale, on loan from Fulham.
Paul Benson guided a tame header that failed to trouble Stockdale and a Glen Southam shot was deflected away.
Ritchie produced another half-hearted shot before Solomon Taiwo's thundering free-kick from 25 yards felled Mark Hudson when he stepped into the line of fire.
Another Benson effort was easily saved by Stockdale and Ritchie smashed another free-kick into the wall.
Rotherham created the best of the early opportunities, but failed to make it count. Dale Tonge's free-kick found Sharps but his powerful header drifted wide and a Drewe Broughton header was well held by Tony Roberts.
Leading scorer Reid might had added to his eight-goal tally when Micky Cummins triggered his run with a deft pass, but under pressure Reid's hurried shot was over Roberts but squirmed wide.
And when Hudson squeezed through a rare gap in the Daggers defence he fired a promising shot that Roberts diverted for a corner.
But two minutes into the second half Dagenham went ahead with their first effort on target, when Ritchie was left unmarked in the area to head in Taiwo's cross.
The visitors were almost gifted a second goal a minute later when a sloppy backpass from Danny Harrison let in Ritchie again, to give Stockdale a heart-stopping moment as he dived at the Dagenham man's feet and forced him wide.
And as Rotherham failed to clear, Ritchie pounced again and rifled a dangerous angled shot that Stockdale dropped to save at the near post.
The Rotherham keeper stopped Dagenham in their tracks again when 16-goal Benson darted in with the home side appealing for an offside flag, Stockdale reacted quickly and blocked at his feet.
And when strike partner Ben Strevens threatened to stretch the lead, bursting into the area, Stockdale again saved well. But then at the death Sharps struck.