Contepomi was on target with an 18-metre penalty but the wind was so strong it blew the kick back out through the posts and had referee George Clancy reaching for his rulebook before he confirmed the score.
But with that blustery wind behind them, Connacht nabbed an injury-time try.
Conor O'Loughlin linked with Dunne before Matthews was sprung on a looping run and sent in under the posts.
Matthews was marking his first start since damaging his ankle in November and Dunne's conversion edged Connacht 10-3 ahead at half-time.
Contepomi's penalty and then his conversion after Horgan's try edged Leinster into a 13-10 advantage and the Argentinian followed up with a penalty on the hour mark.
The Connacht forwards produced an electrifying finale but the 14 men of Leinster hung on.