The reigning European champion looked in danger of losing for just the second time in Pro14 action this season when it trailed 29-12 midway through the second half at The RDS.
Connacht cut loose to run in four tries against a side that tops the table in Conference B, five-eighth Jack Carty scoring one of them to go alongside his nine-point haul with the boot.
However, Leinster stormed back to win in dramatic circumstances in Dublin. Ross Byrne converted tries from Sean Cronin and Dan Leavy before Porter completed the turnaround by barging his way over from close range.
Meanwhile, Conference A leader Glasgow Warriors slipped up against Edinburgh in the first of three meetings in this season's 1872 Cup.
Duhan van der Merwe crossed twice — both after intercepting passes — as Edinburgh ran out a 23-7 victor at Murrayfield, with the rivals due to meet again at Scotstoun Stadium on 30 December (AEDT).
Richard Cockerill's side has now won seven on the spin at home in the league this season, with this latest triumph lifting it to fourth in Conference B.
On a day when derby fixtures took centre stage in the competition, Ospreys ended a run of 10 successive defeats by beating Scarlets 19-12 at Liberty Stadium.
Luke Morgan scored the only try of the game in the all-Welsh battle, the winger hacking a loose pass through with his boot before winning the race to the loose ball.
Sam Davies was successful with the conversion as he finished with a personal haul of 14 points, including two drop goals that gave the hosts breathing space in the second half.