Leinster had only lost once at home to Irish opposition since 2005 and looked to be back on track in the league after consecutive wins over Scarlets and Aironi.
But Connacht clearly hadn't read the script in the first half as they looked to record their fourth win of the season.
It was the visitors who flew out of the blocks with Niall O'Connor making up for missing an early penalty by slotting his second opportunity after ten minutes.
Isa Nacewa drew the European Champions level straight after following Connacht prop Dylan Rogers' being sent to the sin bin.
But once O'Connor had restored the visitors advantage, second row Devin Toner went over to give Leinster an 8-6 lead midway through the half.
Connacht fought back brilliantly towards the end of the half with Ray Ofisa Treviranus giving them back the lead with a try on 30 minutes, O'Connor adding the extras.
And winger Brian Tuohy stretched the lead three minutes before half-time as he dived over, O'Connor's conversion handing the visitors a 20-8 advantage at the interval.
Nacewa knocked over two penalties and a well-taken third from Ian Madigan, with 20 minutes to go, brought the score back to 20-17.
And a quarter of an hour from time Leinster finally reclaimed the lead as Luke Fitzgerald went over, Nacewa duly adding the extras.
The Fijian full-back added another penalty five minutes from time and a Madigan drop goal, the last kick of the game, cruelly denied Connacht what would have been a deserved losing bonus point.
Leinster are now guaranteed to go into the three-week break in the top three ahead of Munster's clash with the Ospreys and will welcome back their internationals for their next clash away to Edinburgh on October 28.
|Leinster Rugby Score Card|
|Connacht Rugby Score Card|
|Ray Ofisa Treviranus||1||5|