Leinster will take a slender five-point lead into the second leg of their Champions Cup last-16 tie against Connacht after overcoming their dogged inter-provincial rivals in Galway.
Two James Lowe tries saw the visitors move into the lead after John Porch put Connacht ahead inside two minutes.
Hugo Keenan and Leva Fifita traded second-half scores as the hosts refused to let Leinster move out of sight.
The sides will meet again at the Aviva Stadium next Friday.
Over 8,000 spectators packed into the Sportsground as the Galway venue's increased capacity served to enhance the big game feel that accompanied the build-up to a contest between two sides who met only two weeks ago at the same venue.
On that occasion Leinster romped to a 45-8 victory, but spurred on by a rousing home crowd in undoubtedly the biggest game of their season so far, Connacht were never likely to go down as meekly on Friday.
The western province rose to the carnival atmosphere with Porch spearing through a gap in the second minute for a welcome early score after big carries from Bundee Aki and Tom Farrell.
Leinster, heavy favourites having beaten Connacht handsomely in both previous meetings between the sides this season, knew their objective was to weather the early storm before methodically silencing the crowd.
They took the first steps towards this when Johnny Sexton kicked their first points after 14 minutes before Lowe picked a line between two forwards in Connacht's defence before turning on the jets for his first try.
The Ireland wing had to wait just four minutes to get over again - this time sending Hugo Keenan through a gap allowing the full-back to carry up to the line and return the ball to Lowe for a simple finish.
With a 10-point lead Leinster looked poised to take the game by the scruff of the neck, but they could not shake Connacht who remained well in the game thanks to Jack Carty's accurate kicking.
The fly-half's boot saw Connacht reduce the arrears to just four before Leinster again created daylight when Keenan collected a flat pass following a huge Leinster scrum to run in for his side's third score.
Again with Leinster threatening to pull away, Connacht were thrown a lifeline when Jamison Gibson-Park was shown a yellow card for a high hit on Kieran Marmion having been introduced to the action just eight minutes earlier.
The sin-binning re-energised the Sportsground crowd, who rose in voice and urged their team to find a second wind.
The players responded and moved through the phases towards the Leinster line before Fifita found enough space to crash over and bring Connacht within two.
The hosts were just inches from completing a stirring fightback and taking the lead two minutes later as Porch and Conor Fitzgerald made line-breaks only for Oisin Downling to knock on when reaching for the line.
Ross Byrne came on to kick a late penalty for Leinster, who sit in pole position as the tie moves to Dublin next weekend - however, Leo Cullen's side know their place in the quarter-final is far from assured.
Leinster: Keenan; J O'Brien, Ringrose, Henshaw, Lowe; Sexton (capt), McGrath; Healy, Sheehan, Furlong, Molony, Murphy; Doris, van der Flier, Conan.
Replacements: Tracy, E Byrne, Ala'alatoa, Toner, Deegan, Gibson-Park, R Byrne, Frawley.
Connacht: O'Halloran; Porch, Farrell, Aki, Hansen; Carty (capt), Marmion; Burke, Heffernan, Bealham, Thornbury, Fifita; Prendergast, Oliver, Butler.
Replacements: Tierney-Martin, Tuimauga, Aungier, Dowling, Papali'i, Blade, Fitzgerald, Arnold.