Madigan, an unused replacement in Bordeaux, landed five penalties and converted a first-half try from prop Jack McGrath as he steered the double-chasing Irish province into a 22-6 lead. But the Dragons, who were saying farewell to skipper Luke Charteris and fellow Welsh international Aled Brew, battled back to claim two second half tries and close the gap to three points.
Their losing bonus point, courtesy of a 77th minute try from Dan Lydiate and an 85th minute score from Will Harries, enabled the home side to pip Benetton Treviso for ninth place overall in the final PRO12 standings.
There was no final round joy for Leinster's Heineken Cup rivals Ulster Rugby, who were beaten 36-8 on their return to Thomond Park. Munster ran in five tries to finish third overall and earn a trip to the Ospreys on Friday night for the first Play-Off semi-final.
Ulster head coach Brian McLaughlin rested the majority of his starting line-up ahead of thjeir training camp in Portugal this week and can no concentrate on one final game of the season at Twickenham Stadium on Saturday, 19 May.