Edinburgh had looked to be cruising when they entered the final quarter with a 31-10 lead after tries from Greig Tonks, Greig Laidlaw and Netani Talei, with Laidlaw kicking the rest of the points.
However, Dragons, who had led through an early try from Steffan Jones, profited from some poor defending and a wayward pass that produced late tries for Dan Lydiate and Tom Prydie, who contributed the rest of his side's points with the boot.
The defeat leaves Dragons second from bottom in the league table - one place behind Edinburgh and with only Zebre below them.
Dragons started the match well and struck with an opportunist score after four minutes, with Toby Faletau powering into the home 22 before offloading to Jones, who dived in between the posts for the opening score. Prydie added the extras.
The lead lasted 10 minutes before the home side tied matters when Harry Leonard delivered a delightful chip into the arms of Tonks, who touched down and left Laidlaw a simple conversion.
The home skipper then gave his side the lead when he dived over from a close-range ruck.
And he added the extra two points after Talei had powered through two tackles before plunging over for a try in his final appearance for the club before moving to Dragons.
Sean Cox and Andrew Coombs were yellow carded after a punch up and Dragons were further depleted when Ross Wardle was sent for 10 minutes in the cooler following a dangerous tackle that presented Laidlaw with a penalty which he steered between the sticks.
And the same player had the final word before the break when he landed a second penalty, cancelling out an earlier effort by Prydie to leave Edinburgh 25-10 up at the pause.
Dragons made a solid start to the second half but had only a missed penalty to show for their efforts, and it was the Scots who boosted their points tally when Laidlaw landed two further penalties.
However, just as the home side were starting to contemplate only their seventh win of the season, Lydiate raced over for a try which Prydie converted.
And the winger hauled his side right back into the contest when he latched on to a loose pass from Nick De Luca inside the Dragons half and galloped over. His conversion trimmed the deficit to seven points and ensured there could be no easing off in the home ranks.
And there were several tense moments among the Edinburgh players before they could celebrate the success.
- Sports & Recreation
- Greig Laidlaw
- Tom Prydie
- Greig Tonks
- Dan Lydiate
- Steffan Jones
- Netani Talei