Joe Schmidt's men ended 2012 on a winning note, with McGrath's 73rd-minute try - his first in this season's RaboDirect PRO12 - confirming the result at the RDS Arena.
Connacht had a strong wind at their backs in the opening half, but failed to register any score to reflect their dominance of territory.
It was left to fly-half Madigan to clinically pick off a converted try closing in on the break, profiting from his own quickly taken penalty.
He added a second-half penalty and the extras to McGrath's late score as Connacht suffered their second festive derby defeat in a week.
Eric Elwood's side were unable to build on a fine early break from winger Danie Poolman as Leinster regrouped in a physical first 10 minutes.
Leinster's forwards grew into the contest, carrying well at close quarters, but the Michael Swift-inspired Connacht were finding holes in the hosts' defence.
Poolman just miscued a grubber kick as he latched onto a cross-field delivery from Dan Parks and Leinster snatched a crucial turnover after a dangerous catch and run from Robbie Henshaw.
Having gained ground in a scrum, Parks was presented with his first shot at the posts but pulled the 14th minute penalty to the left and wide.
Lacking any territorial hold, Leinster had to maintain their discipline in defence and Jordi Murphy and Ben Marshall put in some meaty challenges.
Smart running from Andrew Conway and Fergus McFadden got Leinster into firing range near the half hour mark, and they showed the visitors exactly how potent they can be.
Andrew Goodman and Dominic Ryan both barged defenders as the men in blue gained further momentum and a quick tap penalty from Madigan saw him break out of a tackle to score from close range.
The fly-half added a tricky conversion from the right and boosted by the seven-pointer, Leinster continually got over the gain-line as half-time approached.
On the restart, Brendan Macken went close to intercepting a high pass from Parks as Connacht looked to move the ball wide.
There was no sign of the midfield traffic giving way until Leinster sparked a series of pick and goes with 50 minutes on the clock.
Dominic Ryan, McFadden and stand-in captain Isaac Boss were heavily involved before Devin Toner was held up over the try-line. Connacht held out though, winning a turnover from the resulting scrum.
Madigan did increase Leinster's lead with a well-struck penalty towards the end of the third quarter.
Connacht showed flashes of clever attacking play, most notably when scrum half Kieran Marmion broke from a ruck near halfway and chipped towards the corner.
However, solid Leinster defence and cheap turnovers kept Connacht away from the whitewash and without a score to show for their efforts.
Having turned down a kickable penalty, Brett Wilkinson knocked on a pass from the ensuing lineout. Marshall then blocked an attempted kick from Parks and Leinster broke downfield.
The hosts pulled Connacht through phases of strength-sapping defence in the closing stages and the pressure told when McGrath, supported by Toner, thundered over to the right of the posts.
Leinster hunted for a third try in the dying minute with teenage replacement Adam Byrne threatening on the right wing, but they had already done enough to get their play-off push back on track.
- Sports & Recreation