Contador had attacked early on the six kilometre finishing climb of the Peña del Águila, quickly opening a gap over a chasing group of Pinot and the Team Sky trio of Wout Poels, Diego Rosa, and Mikel Landa as race leader Alejandro Valverde (Movistar) seemed to be in trouble behind.
But while Contador had gone for broke, Pinot and Valverde were pacing themselves well, and while Valverde was able to ride his way back across to the small chasing group to limit his losses to seven seconds, Pinot had bigger aspirations.
The Frenchman rode away from the Team Sky riders, and as the climb flattened out in the final kilometre he had Contador in his sights.
It was an agonising wait as Pinot clawed his way across the final few bike lengths to reach Contador's back wheel, where he waited for just a second before launching a stinging attack to win the stage for a few bike lengths.
Despite missing out on the stage win, Contador gained enough time on Valverde to move into the leader's jersey, while Pinot moved up to second.
The queen stage of the Ruta del Sol saw a five man breakaway group escape early. Tim Wellens (Lotto-Soudal) was the first to go on the attack, being joined by Antonio Nibali (Bahrain Merida), Georg Preidler (Team Sunweb), Felix Grosschartner (CCC Sprandi Polkowice), and Xandro Meurisse (Wanty-Groupe Gobert).
The group worked well together, building up a gap of more than eight minutes to the peloton with 100km gone of the 177.9km stage.
Trek-Segafredo, Team Sky, and Movistar all shared chase duties, and as the gap began to fall in the second half of the stage, Wellens went on the attack from the break, first dragging Grosschartner with him, and then going solo on the ramps of the second category Puerto de las 7 Pilillas climb with 50km remaining.
At that point the Belgian had an advantage of more than six minutes, looking smooth and comfortable as he looked to pick up his second victory of the season in a similar manner to his first.
However Wellens's progress was not all smooth, as he lost grip on his back wheel at a roundabout with just over 30km to go, hitting the deck before leaping back on his bike only a little road rash to show for it.
The same roundabout caused problems in the peloton as a number of riders also crashed, although the main contenders at the front of the group were unaffected.
Much of the final 30km was uphill, and with Trek-Segafredo and Team Sky sitting on the front of the peloton Wellens's advantage steadily fell, dropping below two minutes for the first time on the penultimate climb of the day with 15km to go.
By the time Wellens reached the bottom of the final climb, the Belgian was within sight of the Vasil Kiriyenka-led peloton, throwing in the towel as the road narrowed and ramped up.
The first attack of the climb came from Warren Barguil (Team Sunweb), briefly opening a gap before being pulled back into the fold by Team Sky's Mikel Nieve, before a counter-attack from Nieve's team-mate Mikel Landa.
The Spaniard quickly established a 15 second gap before settling into a rhythm on the nine per cent gradients. Landa looked smooth, but hardwork from Trek-Segafredo's Fabio Felline clawed Contador back into contention.
And as soon as Felline peeled off with 2.5km to go, Contador's attack came, jumping over the top of Landa and dropping all of the other race contenders.
The attack caused chaos behind, with a Thibaut Pinot leading the chase ahead of the Team Sky trio of Poels, Landa, and Diego as race leader Alejandro Valverde was unexpectedly dropped with Ion Izagirre (Bahrain-Merida), quickly conceding 25 seconds to Contador.
But as the gradient flattened out near the top of the climb, Pinot managed to grab on to the coat tails of Contador, with the Frenchman catching his breath for a second, before coming over the top of the Spaniard to win the stage by a comfortable margin.
Behind, Valverde had paced himself perfectly on the steep slopes, joining up with Rosa and Landa, before finding a final burst of speed to come home third, only seven seconds down on Pinot.
Tomorrow's 12 kilometre time trial looks like the last chance for riders to shake up the top of the general classification, with two flat finishes stages four and five.
Ruta del Sol stage two, Torredonjimeno - Alto Peña del Águila, Mancha Real (Jaén), (177.9km):
1. Thibaut Pinot (Fra) FDJ, in 4-44-03
2. Alberto Contador (Esp) Trek-Segafredo at 2 seconds
3. Alejandro Valverde (Esp) Movistar Team at 7s
4. Ion Izaguirre (Esp) Bahrain-Merida, same time
5. Mikel Landa (Esp) Team Sky, at 9s
6. Diego Rosa (Ita) Team Sky, st
7. Wout Poels (Ned) Team Sky, at 13s
8. Sébastien Reichenbach (Sui) FDJ, at 28s
9. Pieter Weening (Ned) Roompot - Nederlandse Loterij at 46s
10. Floris De Tier (Bel) Team LottoNl-Jumbo, st
Overall classification after stage two
1. Alberto Contador (Esp) Trek-Segafredo, in 8-46-33
2 Thibaut Pinot (Fra) FDJ, at 3s
3 Alejandro Valverde (Esp) Movistar Team, at 5s
4 Jon Izaguirre (Esp) Bahrain-Merida, st
5 Diego Rosa (Ita) Team Sky, at 7s
6 Wout Poels (Ned) Team Sky, at 11s
7 Mikel Landa (Esp) Team Sky, at 12s
8 Sébastien Reichenbach (Sui) FDJ, at 26s
9 Rigoberto Uran (Col) Cannondale-Drapac, at 49s
10 Pieter Weening (Ned) Roompot - Nederlandse Loterij at 1-08
Thank you for reading 20 articles this month* Join now for unlimited access
Enjoy your first month for just £1 / $1 / €1
*Read 5 free articles per month without a subscription
Join now for unlimited access
Try first month for just £1 / $1 / €1