The Welsh region had fought back to 13-13 thanks to replacement Kris Burton knocking over a simple penalty five minutes from full-time. However the former Italian fly half went from hero to villain when his re-start from the 22m line went directly into the touch with the match nearing the final whistle.
The Edinburgh pack, which had been dominant all night, went for one last shove and earned a penalty to give young Leonard his chance for glory. The 21-year-old stepped up and rammed his shot between the uprights to leave the Dragons with just a losing bonus point instead of the three they would have claimed with a draw.
Edinburgh edged 6-3 in front at the break and increased the lead when winger Tim Visser crossed the whitewash. But Dragons hit back through scrum half Richie Rees who scored against his former teammates with a clinical finish.
The Men of Gwent had won six of their last eight clashes with Edinburgh and arrived at Murrayfield buoyed by a 15-8 success against Ulster.
Jason Tovey kicked one from two penalties in a first-half and the Dragons fly-half converted Rees’s clever score on 53 minutes.
With both sides guilty of failing to execute basic passes and the game bogged down in midfield, it looked very much like the points would be shared when Burton’s penalty sailed over after Denton was ruled offside following a tackle on another former Edinburgh man, Netani Talei.
However Leonard had the final, and most crucial say, when he secured victory with the last kick of the game.