The pair touched wheels on lap 38 of 66 at the Circuit de Catalunya as Ferrari’s Vettel exited the pits and managed to prevent Hamilton taking the lead.
But his advantage was short lived as Hamilton took advantage of having the quicker soft tire on his Mercedes and powered past Vettel with 22 laps remaining, holding off his arch rival to take the checkered flag.
Australia’s Daniel Ricciardo finished a distant third for Red Bull.
Hamilton has cut the gap on Vettel at the top of the standings to six points after five rounds of this year’s Formula 1 championship with his second victory of the season and 55th overall.
His teammate Valtteri Bottas, winner of the previous round in Russia, saw his race ended when his engine blew on lap 40 while in third place.
Other than the titanic battle at the front, the other major talking point was the first corner tangle between last year’s Spanish Grand Prix winner Max Verstappen in the Red Bull and Vettel’s teammate Kimi Raikkonen.
The pair came together on the first corner after Bottas appeared to make contact with Raikkonen to send him off line.
For teenage star Verstappen it was a disappointing early exit after his heroics of last year, but for a young fan of Raikkonen the sadness was even greater as he was captured by the cameras bursting into tears.
In a heartwarming gesture, the youngster was later found by race officials and taken to the Ferrari team area to meet his hero.
Vettel, bidding for his third win of the season, looked in good position after jumping polesitter Hamilton at the start and building up a comfortable early lead.
He was briefly held up at the first round of pit stops by Bottas, who stayed out to help his teammate, but a brilliant overtaking move saw the German re-establish his advantage.
A virtual safety car after Stoffel Vandoorme and Felipe Massa clashed gave Hamilton the chance to pit earlier than Vettel and close the gap, paving the way for a brilliant victory.
“A fantastic job this weekend — thank you. The strategy was right on it,” Hamilton told his team after crossing the line in triumph.
The Force India pair of Mexican Sergio Perez and Frenchman Esteban Ocon took an excellent fourth and fifth with German Nico Hulkenberg in sixth for Renault
Home hero Fernando Alonso was unable to capitalize on his fine performance in qualifying and finished 12th in the McLaren.