Wales had trailed the series 1-0 following last week's 27-19 loss in Brisbane but they came out firing down the coast as they looked to keep their summer alive.
George North gave the hosts the perfect start with a try inside four minutes.
Berrick Barnes chipped away at Wales' lead and created the opening for Rob Horne as the Lions' next Test opponents entered the interval with a 13-7 lead.
Wales instantly hit-back with a Jon Davies try after Will Genia threw an aimless pass and Ashley Beck hacked through.
Halfpenny and Barnes continued to exchange shots at goal as the lead swung from side to side.
But a 67th minute long-range penalty from Halfpenny appeared to be the difference as Wales hung on.
That was until injury time and an Australian driving lineout, which resulted in a penalty.
Replacement fly-half Mike Harris stepped up and nailed the penalty on the death to heap the misery on northern hemisphere sides following Ireland's own agony at the hands of New Zealand earlier in the day.