Leigh Halfpenny's fourth successful penalty had Cardiff leading 17-12 as the game entered the final quarter.
But Contepomi brilliantly held his nerve to boot three crucial penalties in the closing stages, the last of which came after the Blues had regained the lead with a Nicky Robinson drop goal.
These sides duelled out a 16-16 draw at the Arms Park in September and a close game was always on the cards as Contepomi and Halfpenny peppered the posts.
Early penalties from the Leinster centre in the 16th and 26th minutes gave the hosts a 6-3 lead, with Halfpenny keeping the Blues in touch.
Bidding to follow in the footsteps of previous RDS winners the Scarlets, Cardiff placed huge pressure on the Leinster pack and after Halfpenny's second penalty, it was no surprise when the visiting forwards helped propel Andy Powell over for an unconverted 30th-minute try.
Leinster lorded possession in the closing 10 minutes of the opening half, notching a third penalty through Contepomi.
Michael Cheika's men were close to sniffing out a try but Brian O'Driscoll was just short of the try-line, held up by Tom James' superb cover tackle.
The hosts began the second half in determined fashion, with Contepomi continuing to be unerring in front of the posts.
He edged Leinster 12-11 ahead but Wales starlet Halfpenny was showing little sign of nerves at the other end, picking off penalties in the 56th and 66th minutes.
However, the introduction of former South Africa international Ollie Le Roux really spurred on the home side and their large vocal support really made their presence felt.
Scrum half Chris Whittaker was also heavily involved in Leinster's resurgence. O'Driscoll again edged towards the whitewash in the 74th minute, only to be denied by Cardiff's resilient defence.
With try-scoring opportunities limited, Leinster forced a flurry of late penalties which the classy Contepomi converted.
Two in quick succession had Leinster 18-17 ahead and although Robinson helped himself to an opportunist drop goal, Contepomi had the final say as Leinster closed the gap on league leaders Munster to two points.