Derrick Lee gave away a controversial penalty try but scored at the other end as Edinburgh broke their Celtic League duck at Murrayfield.
Edinburgh: (12) 35: Tries: Lee, Pyke. Cons: Paterson 2. Pens: Paterson 7.
Blues: (13) 16: Try: Penalty. Con: Macleod. Pens: Macleod 3.
But it was seven penalties and two conversions from Chris Paterson that was the difference between the teams.
Kicks from Nicky MacLeod and the penalty try after Lee nudged Dean Dewdney put the Blues in control.
But Lee finished off a flowing Edinburgh move before Michael Pyke's interception try settled the game.
It was a Paterson penalty after four minutes that had put Edinburgh in front.
Cardiff responded and Tom Shanklin looked certain to claim a try in the corner until a frantic last-gasp challenge by Paterson forced him to tread on the touchline.
The referee had been playing advantage and MacLeod landed the penalty equaliser.
Paterson quickly restored the advantage with a kick from 40 metres and added another from closer range.
But Cardiff seized the initiative before the break when scrum-half Dewdney hoofed a loose ball into the touchdown zone.
He and Lee embarked on a head-to-head sprint that appeared to be a 50-50 contest.
Lee nudged Dewdney aside and, to the disgust of the Edinburgh fans, referee Simon McDowell awarded the gift try, with MacLeod adding the formality of a conversion.
MacLeod banged over another penalty after Todd Blackadder was adjudged to have pounced on the ball before it was free from the back of a ruck.
Edinburgh edged back into the game on the stroke of the interval as Paterson made it four goals out of four.
He struck again to snatch back the lead, only for MacLeod to reply in identical style two minutes after Blues flanker Mark Lewis was sent to the sin-bin for illegally entering a ruck from the side.
Paterson again responded following a powerful pack drive before Mike Blair started the move that led to Edinburgh's first try.
Hugo Southwell then Ally Hogg were also involved before Lee was released to cruise to the target from 30 metres.
And the win was sealed when substitute Pyke raced in for an interception try from halfway, again goaled by Paterson.
"We had enough possession, but did nothing to give them problems," said Blues coach Dai Young.
"There were a lot of mistakes from both sides as we both came in desperate for a result, but credit to Edinburgh for a really gutsy performance."
Edinburgh: Lee, Southwell, Di Rollo, Joiner, Paterson, Laney, Blair, Jacobsen, Hall, Smith, Hines, Kellock, Blackadder, Hogg, Callam.
Replacements: Kelly, Brannigan, Pringle, S. Cross, Lawson, Godman, Pyke.
Cardiff Blues: R. Williams, Tuilagi, James, Shanklin, Morgan, Macleod, Dewdney, Jenkins, G. Williams, M. Jones, Quinnell, D. Jones, M. Lewis, M. Williams, Schubert.
Replacements: R. Thomas, A. Lewis, Sidoli, Budgett, L. Thomas, R. Smith, Nuthall.
Referee: Simon McDowell (Ireland)