Polanc (Lampre-Merida) finished ahead of Sylvain Chavanel (IAM) but all eyes were on the next three riders who followed him across the line.
Fabio Aru (Astana) crossed third, with Contador (Tinkoff-Saxo) and Australia’s Richie Porte (Sky) on his wheel.
The three favourites established their dominance over the race with five kilometres to go after Contador attacked the peloton with Aru and Porte sticking close to his wheel.
Aru had the short term support of team-mate Mikel Landa but ultimately it was a three-rider contest with Contador and Porte.
"My attack wasn't planned. I felt good, looked around, and went," Contador said. "Aru and Richie Porte are strong, but Urán and others were dropped and I'm happy with the situation after five days.
"I didn't expect the Maglia Rosa, but to have it is always fantastic. It's a nice present, and a real honour. I love the Giro d'Italia, the people and the country, and to wear the Maglia Rosa tomorrow during the stage will be fantastic, although the one that counts is the Maglia Rosa in Milan, so if someone else takes it tomorrow, it won't be a problem."
After the frenetic pace throughout the previous stage this one was a sleepy affair until the final ascent to Abetone.
Stage winner Polanc, Axel Domont (AG2R), Serghei Tvetcov (Androni Sidermec), Silvan Dillier (BMC) and Sylvain Chavanel (IAM) set the pace early and carried a 10 minute plus lead for a significant period of the stage.
Even with 20km to go and as the beginnings of the climb started to pinch, the time gap to the peloton was eight minutes, but there was movement coming from behind.
Chavanel was the first to shatter the detente of the break with an attack but was immediately followed by all but Tvetcov. Further attrition took care of Domont and shortly after Polanc was alone at the head of the race.
Behind the peloton was changing shape as Astana and Tinkoff-Saxo massed at the front. The steady but hard effort combined to shed the large group one rider at a time.
The stage blew apart with an attack by Contador as Porte, Aru and Esteban Chaves (Orica-GreenEDGE) quickly responded.
Chaves could not sustain the pace set by his more experienced rivals and fell off but ahead Polanc was confirming himself as the winner with a gutsy finish.
"The day I came to the Giro, I turned 23, so this is a wonderful birthday present. It feels strange, and hard to believe. I don't think I'll sleep tonight," Polanc said.
"My legs were good today, and my goal was to build a big lead, and then worry about who was the strongest. I'm a good climber, but the climb isn't steep and Chavanel is a good rider. When I was on my own, they told me the chase behind was fast, but when I heard my gap, I knew that I would win."
Stage 5: 152km, La Spezia - Abetone
1 Jan Polanc (SLO) Lampre-Merida 4hr 9min 18sec
2 Sylvain Chavanel (FRA) IAM 0:01:31
3 Fabio Aru (ITA) Astana
4 Alberto Contador (ESP) Tinkoff-Saxo
5 Richie Porte (AUS) Sky
6 Mikel Landa Meana (ESP) Astana 0:01:44
7 Dario Cataldo (ITA) Astana 0:01:53
8 Yury Trofimov (RUS) Katusha
9 Damiano Caruso (ITA) BMC
10 Darwin Atapuma (COL) BMC
1 Alberto Contador (ESP) Tinkoff-Saxo 16hr 6min 54sec
2 Fabio Aru (ITA) Astana 0:00:02
3 Richie Porte (AUS) Sky 0:00:20
4 Roman Kreuziger (CZE) Tinkoff-Saxo 0:00:22
5 Dario Cataldo (ITA) Astana 0:00:28
6 Esteban Chaves (COL) Orica-GreenEDGE 0:00:37
7 Giovanni Visconti (ITA) Movistar 0:00:56
8 Mikel Landa Meana (ESP) Astana 0:01:01
9 Davide Formolo (ITA) Cannondale-Garmin 0:01:15
10 Andrey Amador (CRC) Movistar 0:01:18