The Lotto-Belisol man timed his break to perfection with approximately three kilometres remaining to cross the line ahead of John Degenkolb, who missed out on a fifth stage win on Friday.
Degenkolb (Giant-Shimano) led a cluster of riders to the finish behind Hansen and can take solace from the fact his grasp on the green jersey for leading the points classification appears unlikely to slip with just two stages remaining.
Filippo Pozzato (Lampre-Merida), Yannick Martinez (Europcar) and Michael Matthews (Orica Green-Edge) rounded off the top five.
Friday's race saw no movement in the general classification, with the lead contenders not involved in the finish, perhaps a sign they were saving their energy for Saturday's tricky 20th stage.
Contador (Tinkoff-Saxo) retains the red jersey with a lead of one minute and 19 seconds over Chris Froome (Team Sky).
An initial three-man breakaway was soon established on the 180km route from Salvaterra do Mino to Cangas do Morrazo.
Laurent Mangel (FDJ.fr), Pim Ligthart (Lotto-Belisol) and Wouter Poels (Omega Pharma - Quick-Step) had gained a lead of over two minutes by the time they reached the summit of the day's first climb.
However, with just under 30km remaining the trio's advantage was cut to just 45 seconds and they were swept up by the peloton in no time.
Astana's Alexey Lutsenko made a break on the second climb and reached the descent with a lead of 19 seconds.
Lutsenko was caught with 5km to go, though, and a bunch sprint for the finish seemed likely with Giant-Shimano and Orica Green-Edge leading the way.
Hansen's break came with roughly 3km to go, although it seemed likely the peloton would reel him in.
That scenario failed to occur, however, and the Australian was 11 seconds clear heading into the final kilometre.
The chasing pack came into view when Hansen reached the home straight but he held on to reach the line ahead of Degenkolb and seal an impressive breakaway win.