Cardiff boosted their chances of a top-six finish in the PRO12 with a barely deserved 18-17 win over Edinburgh in an error-strewn game.
Flowing rugby was at a premium in testing conditions in the Scottish capital and the home side played most of what was on show. They scored a first-half try through captain Neil Cochrane, converted by Sam Hidalgo-Clyne, before Rory Scholes bagged a double in the second period.
That saw Edinburgh leading 17-6 heading into the final 20 minutes and seemingly on course for victory, but Cardiff hit back.
Sion Bennett's try was converted by Steve Shingler - adding to his two penalties from the first half - to reduce the deficit before Lloyd Williams crossed for what would prove to be the match-winning score as Blair Kinghorn missed a late penalty for the hosts.
After a subdued opening seven minutes in which neither side visited the opposition 22, the first opportunity fell Cardiff's way when the hosts were penalised for not rolling way at the breakdown. Shingler banged over the 40-metre kick to open the scoring.
Edinburgh, who were playing against the elements, responded with a spell of pressure that yielded a series of three penalties and a yellow card for Cardiff prop Anton Peikrishvili.
All three penalties were booted into touch and a powerful drive following the third lineout shunted the Cardiff defence backwards, allowing Cochrane to touch down the game's opening try.
Cardiff immediately cut the deficit to 7-6 when Shingler landed his second penalty of the half before Hidalgo-Clyne missed a three-pointer of his own when his 45-metre penalty went wide.
The Cardiff penalty tally continued to mount and, having warned the Welshmen, the referee lost patience, sending Jarrad Hoeata to the sin bin after half an hour.
As they had done with the previous sin-binning, Cardiff shrugged off their numerical disadvantage and finished the half the stronger of the two sides.
However, a string of errors in sight of the target meant they failed to add to their points tally and Edinburgh reached the interval with a single point advantage.
On the overall balance of play, Edinburgh should have been further ahead and they restarted with intent as they sought to remedy that situation. And after dominating the opening eight minutes of the second period, they grabbed a second try.
Jason Tovey freed Chris Dean who offloaded to Scholes, and the Irishman raced down the right flank to dot down in the corner.
The conversion was missed but Edinburgh further extended their lead in the 55th minutes, with Scholes again the scorer.
Damien Hoyland almost dodged between two defenders but was held just short of the whitewash. However, Scholes was lurking outside and he took a pop pass then plunged over for his second unconverted score.
Cardiff struck back with just over an hour on the clock, with Hoeata making the initial break into the home 22 and Bennett eventually completing the job between the posts to leave Shingler a simple conversion.
Sensing that the game was there to be won, Cardiff belatedly came to life and they snatched the lead when Williams darted through on a speculative chip ahead and read the bounce well to touch down between the sticks.
Shingler's conversion attempt was charged down, leaving the visitors with a one-point advantage entering the final six minutes.
That proved to be enough, though, as Kinghorn missed with a long-range penalty effort that proved to be Edinburgh's final scoring opportunity, and the narrow defeat bonus was little consolation for the Scots, who have now lost four successive league matches.