The Blues started well and were 10-0 ahead by the break thanks to a try from the fit-again Chris Czekaj after a brilliant off-load from Xavier Rush. Halfpenny should have scored another one, but couldn't hold on to the final pass.
Even so, the Wales and British & Irish Lions wing landed a 40 metre penalty and converted Czekaj's try to give the visitors a useful interval lead. David Blair notched the home side's first points at the start of the second half, but Halfpenny struck again with a penalty to restore the 10 points gap.
A third penalty for the Blues' star made it 16-3. Edinburgh finished strongly as they tested the Welsh region's defensive capabilities to the full.
Blair added a second penalty and then Tim Visser raced over for his 11th try of the season to steal a losing bonus point at the death.