Edinburgh survived a major scare to claim a bonus-point victory over bottom side Zebre Parma in the United Rugby Championship.
First-half tries from Charlie Shiel and Jack Blain saw the home side go in 10-0 up at the break.
A brace of Simone Gesi tries and one from Tiff Eden swung the match in Zebre's favour at 17-10.
Connor Boyle's touchdown levelled things before Paddy Harrison's try in the last play won it for Edinburgh.
After a run of one win in their last six - including a back-to back derby defeats to Glasgow Warriors - the only acceptable outcome for Edinburgh against the league's bottom side was the maximum five points.
Zebre have failed to win a single match this season, though they did give Glasgow a minor scare in Parma in December.
But after Shiel darted off the back of a maul to touch down on 17 minutes there should have been little doubt which way this one was going.
A searing break from Mark Bennett should have brought a try only for the final pass to hit the deck, but moments later Bennett got his timings right to set Nick Haining free and he in turn fed Blain to go over in the corner.
The Italian side looked there for the taking, but some sloppy handling robbed the home side of any sustained pressure and they had to make do with only a 10-point lead at the break.
That advantage was halved early in the second period as scrum-half Allesandro Fusco fired a long pass out to wing Gesi to dive over after a period of sustained Zebre pressure.
If that was concerning for the home support, worse was to come. Fusco was allowed to escape down the short side all too easily and picked his moment to put Gesi over in the corner once more to level things up.
Only a vital turnover from a maul heading towards their line prevented Edinburgh falling behind. Ben Vellacott and Bill Mata appeared from the bench as the hosts looked to wrestle back control, with Mata's ferocious carries helping to turn the tide.
Edinburgh started to hammer the Zebre line, once being held up and then unable to force a rolling line-out maul over the try-line as the visitors escaped unscathed.
That failure came back to bite Edinburgh 13 minutes from the end when fly-half Eden ghosted through some weak Edinburgh defending to go in under the sticks.
Edinburgh desperately needed a response and they got one immediately, Boyle grounding after a rolling line-out maul blasted over, with Blair Kinghorn's conversion levelling the scores again.
The home side threw everything at it in the dying moments and a deafening roar went up as substitute Harrison dived over in the last play to snatch a victory Edinburgh may feel a touch fortunate to have secured.
Edinburgh head coach Mike Blair: "It's funny, when you go through a game, you get a feeling about how it's going, and I actually felt confident".
"When their stand-off scored to put them 17-10 up, I questioned myself a little bit, but I really like the character of the group we had out there - they came through in the end.
"We delivered when it mattered. Why are we leaving it till then to do it? The challenge is to find that intensity of play for the full 80 minutes."