Centre Fergus McFadden restored Leinster's lead after good work from replacement Cian Healy before Madigan sealed the win, denying the Blues the consolation of a losing bonus point.
Elsewhere, Connacht were denied victory in Wales against the Scarlets as Sean Lamont scored with almost the last move of the match to hand the hosts a 35-33 victory in a thrilling encounter.
Connacht seemed set to grab a rare win at Parc y Scarlets thanks to a hat-trick of tries from wing Fionn Carr.
Ian Keatley was successful with all three conversions, while he also kicked three penalties to put Connacht in with a shout of victory.
But Scarlets exploited the numbers when visiting prop Ronan Loughney was sin-binned, Jonathan Davies crossing for his second try before Lamont struck.
Meanwhile, Ulster climbed to second in the table after making it two wins from two in the Magners League with a hard-fought 22-15 win in Italy against Aironi.