Despite being on the back foot for much of the first half, Leinster led 9-6 at the break thanks to three Madigan penalties - the last of them coming after a yellow card for Ulster's Dan Tuohy.
The Ulstermen should have been in front at that stage, especially given the injury-enforced departure of Leinster captain Jamie Heaslip and some passive home defending. Two penalties from the fit-again Ruan Pienaar had given them an early lead.
The visitors fell further behind following an opportunist Madigan try in the 42nd minute, before prop Wiehahn Herbst's first touchdown in Ulster colours cut the gap to 16-11.
But Madigan's fourth successful penalty, coupled with a deserved late try from man-of-the-match Jack Conan, saw Leinster bounce back impressively from last week's disappointing defeat to Munster.
Crisp passing from scrum half Pienaar saw Ulster make early headway, Tuohy tearing through midfield and Leinster required a terrific Fergus McFadden turnover to relieve the pressure.
Leinster enjoyed some attacking phases before Tuohy's bone-crunching tackle on Jack McGrath and follow-up by Darren Cave saw Pienaar go for goal from his own half. His well-struck kick came back off the crossbar.
The South African made amends two minutes later, splitting the posts from just inside the Leinster half, before Madigan responded in the 21st minute following a weaving run from excellent centre Luke Fitzgerald.
Ulster fired back with some potent midfield play as Paddy Jackson and Stuart Olding grew in influence. Leinster were pinged for not rolling away and Pienaar restored his side's three-point advantage.
With a hamstring tweak forcing Shane Jennings' late withdrawal before kick-off, Leinster suffered a second back-row setback with the very rare sight of Heaslip going off injured with a shoulder injury.
Madigan lifted Leinster spirits with a levelling penalty past the half hour mark, the dancing feet of Fitzgerald again outfoxing the Ulster defence initially.
But Leinster enjoyed some welcome territory approaching half-time, with the penalties beginning to stack up against the visitors. Tuohy needlessly dived in off his feet to take out scrum half Isaac Boss and following the Ulster lock's sin-binning, Madigan converted from in front of the posts.
A left wing raid by Madigan and Jordi Murphy, coupled with a strong Zane Kirchner carry near the posts, had 14-man Ulster under immediate pressure in the second period. Crucially, they switched off at a five-metre penalty. Madigan feigned a kick to touch, instead tapping it and rolling out of a Callum Black tackle to touch down.
Leinster's talisman added the conversion but Neil Doak's charges created a well-worked try seven minutes later, tighthead Herbst driving over to the right of the posts with support from fellow South African Franco van der Merwe.
Pienaar was unable to convert at 16-11 and after Devin Toner went close during a power-packed spell of carrying, Madigan's reliable right boot put eight points between the sides.
Pienaar was wide and short with a left-sided penalty entering the final quarter, and Ulster's challenge gradually petered out.
Leinster duly closed out their fifth successive victory over their provincial rivals with a try from flanker Conan, who burst on to Luke McGrath's short pass to go over in the left corner.