The League Two side went out 4-2 on penalties, after the teams had shared 12 goals over the preceding 120 minutes.
Stuart Dallas’ quickfire double put Brentford in control, and though George Porter pulled one back, Nick Proschwitz profited from indecisive home defending to restore the two-goal cushion for the visitors.
Ashley Chambers gave the east London hosts hope on the stroke of half-time, and Andre Boucaud’s 25-yard strike deceived Richard Lee in the Bees goal to level matters.
Brentford substitute Andre Gray scored a fourth to put the visitors in front again late on but Ashley Hemmings forced extra-time with a shot from an acute angle.
Montell Moore restored the Bees’ lead in extra-time, only for Jamie Cureton to hit back once again.
The Daggers went in front for the first time when Hemmings netted his second goal of the game – but Harlee Deen forced penalties.
Jack Connors and Chambers missed spot-kicks for the hosts and Bees skipper Kevin O’Connor slotted past Liam O’Brien to ensure Mark Warbuton’s side progressed into the second round.