Stephane Peterhansel took a shock lead at the Dakar Rally after winning the penultimate stage of the race.