MONTMELO, Spain — Thanks to superior strategy and some help from his teammate, Lewis Hamilton tightened the early title race in Formula One after beating Sebastian Vettel to win the Spanish Grand Prix on Sunday.

Hamilton saw his advantage of a pole position evaporate when Vettel beat him to the first corner, but Mercedes' decision to have Hamilton finish the race on faster tires allowed the British driver to overtake Vettel's Ferrari with more than 20 laps left.

Hamilton would have had to leave his challenge until late if not for some assistance from teammate Valtteri Bottas, who held up Vettel before the Finn's Mercedes broke down in a puff of smoke.

"This was the rawest fight I have felt in a long time. This is what the sport is meant to be, this is why I race - to have battles with him for the championship," Hamilton said. "I just really have to congratulate and thank my team. They did a wonderful job with the strategy and the pit stops."

Hamilton's second win in five races this season cut Vettel's lead from 13 points to six heading into the Monaco GP. It was the three-time world champion's 55th career victory and his second at the Circuit de Barcelona-Catalunya after first winning here in 2014.

Daniel Ricciardo brought his Red Bull across in a distant third place to complete the podium, his best result of the season.

Montreal's Lance Stroll, 18, finished in 16th place.

Vettel had a great surge from second on the grid, going past Hamilton to the first right-hand turn and staying in front just as his Ferrari partner's race ended.

Starting from fourth and fifth, Kimi Raikkonen and 2016 race winner Max Verstappen came together when trying to squeeze around the first turn with Bottas alongside them. Bottas nudged Raikkonen into Verstappen, with the contact damaging the front suspensions of the Ferrari and Red Bull.

"It all started when I got hit, my car jumped a bit and you cannot control after that," Raikkonen said.

After Vettel and Hamilton had both pitted, Vettel hunted down Bottas now in the lead and engaged him in a lap-long duel. Vettel eventually got by on a third try, but by then Hamilton had pulled back some valuable seconds.

The two title rivals jousted after Vettel came out of his second pit stop just inches ahead of the hard-charging Hamilton. They brushed going through the first of two turns, with Hamilton going off momentarily as Vettel defended his position.

The teams' tire strategy then came into play.

While Vettel used his two sets of faster tires first before finishing on the more long-lasting but slower ones, Hamilton used his more conservative tires after his first pit stop, allowing him to finish on the faster set.

"If we had had the same tires on, it probably wouldn't have been as exciting" Hamilton said. "At the end I was able to manage the soft tires."

Moments after Bottas saw his hopes of adding to a maiden win in the previous round go up in smoke, Hamilton closed in on Vettel on his faster tires and never looked back after going by on lap 43.

"I was surprised that when I came out we were so close," Vettel said. "I was doing what I could to stay in front, but as soon as I was alone he just flew past."

Force India pair Sergio Perez and Esteban Ocon finished fourth and fifth respectively, the best result for both drivers this year.

Nico Hulkenberg (Renault), Carlos Sainz (Toro Rosso), Pascal Wehrlein (Sauber), Daniil Kvyat (Toro Rosso) and Romain Grosjean (Haas) rounded out the points.

Fernando Alonso got his McLaren through to the checkered flag for the first time this season. He added his hopeful 12th-place finish to the leg of Spanish ham that a fan handed him over a barbed-wire fence while he was greeting his home supporters before the race.

The scrape between Raikkonen and Verstappen wasn't the only incident.

Felipe Massa collided with both McLaren cars. Alonso managed to keep control after they tangled early, but his rookie partner Stoffel Vandoorne abandoned midway through when his suspension was bent after the knock with Massa's Williams.