Sebastian Vettel put his Ferrari third ahead of Red Bull’s Max Verstappen and Daniel Ricciardo, barely a quarter of a second off the Mercedes, with team mate Kimi Raikkonen backing him up in sixth.
Both Williams made the top ten, with Valtteri Bottas seventh and Felipe Massa tenth. Between the white cars were the Force Indias of Sergio Perez and Nico Hulkenberg.
Rosberg set the early pace on the soft Pirelli tyres, with a lap of 1m 42.294s, at a time when Finnish twosome Raikkonen and Bottas had been fastest overall on the supersofts with 1m 42.257s and 1m 42.611s respectively.
Hamilton, meanwhile, battled with flat spots on his softs and continually struggled in the second sector, and at one stage feared he had a transmission problem and asked the team to check it while also rebalancing his wheels. It transpired that all was well.
When the wholesale switch to ultrasoft rubber came as everyone started their qualifying simulations, the trick became to generate sufficient heat in the tyres as conditions cooled when dusk fell.
Vettel set the ball rolling with 1m 41.404s and then 1m 41.130s, as Bottas went second on 1m 41.959s. But then Rosberg got wound up with 1m 40.940s. Then Hamilton went out, his car now re-fettled, and banged in a 1m 40.869s to beat his team mate by 0.079s, and Vettel by 0.269s. The Ferrari driver rolled to a halt at the end of the session, reporting suspected gearbox failure.
Behind them, the Red Bulls were very evenly matched, with Verstappen on 1m 41.389s and Ricciardo shadowing him with 1m 41.390s, though the Australian said he encountered some traffic and knew where he could gain more time. Raikkonen was sixth, with 1m 41.464s as Bottas fell to seventh.
The Force India drivers both complained of lack of power on the straights on their way to 1m 42.041s for Perez and 1m 42.264s for Hulkenberg, as Massa rounded out the top 10 with 1m 42.268s.
McLaren had a better showing with Fernando Alonso 11th on 1m 42.366s and Jenson Button getting going after his earlier mechanical problems with 1m 42.823s for 12th. It was another trying session for Daniil Kvyat and Toro Rosso, as the young Russian found himself having a wild spin from Turn 16 to 17 after the left-rear tyre yet again punctured. This time he made it back to the pits, but neither he nor team mate Carlos Sainz went out again as the Italian squad set about investigating the problem.