Leinster have replaced Irish rivals Munster as the Pro12 leaders thanks to a bonus-point win over the Dragons.
Jack McGrath charged over to give Leinster a 10-3 lead at the break but the Dragons hit back with tries from Ashley Smith and Richie Rees.
Leinster's pressure resulted in two penalty tries and Dragons replacement Francisco Chaparro was sent-off in the final minute for a dangerous tackle.
Darren Hudson sprinted over for the bonus-point try deep into injury-time.
Leinster, understrength with eight players on Ireland duty, dominated the first half at the RDS but they had to wait until the 38th minute to break stout resistance from the Dragons.
Madigan slotted over a 14th minute penalty as the hosts seized early control but Jason Tovey levelled six minutes later with a sweetly struck drop goal.
It was a rare foray forward for the Dragons, who were punished for a series of infringements when prop Nathan Buck was sin-binned on 33 minutes.
The visitors suffered a further blow when number eight Nick Cudd was forced off injured, with Jevon Groves coming on as his replacement.
Leicester made the extra man count, with McGrath barging over from close range and Madigan added the extras.
The Dragons stunned Leinster with two tries in two minutes early in the second half.
A long kick upfield was followed by a turnover and ball was passed out wide, with Matthew Pewtner popping the ball up for Smith to touch down after 46 minutes.
Another turnover and the Welsh side were in again, this time quick passing allowing Rees to canter in.
Tovey missed both conversion attempts but he fired over a penalty to give the Dragons a 16-10 lead and the chance to record a first win in Dublin as a region.
Leinster hit back and Dragons replacement Groves was yellow-carded for collapsing a maul as the hosts regained control.
A series of penalties close to the line, courtesy of Leinster's dominant scrum, resulted in a penalty try on the hour mark with another coming in similar fashion six minutes later.
Madigan converted both tries to open up an eight-point gap although the Dragons stayed in touch with a Tovey penalty 10 minutes from time.
There was a dramatic finish to the game after Chaparro was sent-off in the final minute for a dangerous tackle on Issac Boss.
Leinster charged forward and replacement Hudson sprinted in at the corner deep in injury time to clinch the bonus-point and in turn deny the Dragons a losing bonus-point.
Madigan's superb conversion from wide was the final act of a hard-fought victory as Leinster moved two points clear at the summit.
Leinster: Kirchner, McFadden, Macken, Reid, Fanning, Madigan, Reddan, J. McGrath, Cronin, Moore, Cullen, McCarthy, Ruddock, Jennings, Murphy.
Replacements: Gopperth for Reid (61), Boss for Reddan (48), Bent for J. McGrath (68), Dundon for Cronin (72), Furlong for Moore (68), Denton for McCarthy (61), Ryan for Jennings (53), Hudson for Boss (80).
Dragons: Amos, Pewther, Leach, A. Smith, Harries, Tovey, Rees, O. Evans, Thomas, Buck, Hill, Sidoli, L. Evans, Cudd, Talei.
Replacements: S. Jones for Amos (72), Wardle for A. Smith (53), W. Evans for Rees (58), Coundley for O. Evans (65), Parry for Thomas (59), Chaparro for Buck (58), Screech for Sidoli (58), Groves for Talei (33).
Sin Bin: Buck (33), Groves (58)
Sent Off: Chaparro (80)
Ref: Marius Mitrea (Italy)
Assistant Referees: M Patton, B O'Connell (both IRFU)
Citing Commissioner: John Cole (IRFU)
TMO: Kevin Beggs (IRFU)