The win means Hamilton trails his rival by six points at the top of the Formula One World Championship after five rounds. It was the Brit's second victory of the season and 55th overall.
"I really had to burst those tires at the end so that every time [Vettel] reacted and pulled out a quicker time, I could react," said Hamilton.
"I can't tell you how happy I am. I'm super grateful for everyone as I've mentioned before, at the factory."
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's 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.
For the two-time world champion, the next stop is the Indy 500,
while the Formula 1 circus moves on to the iconic venue of Monte Carlo in a fortnight where Hamilton and Vettel are set to resume their battle for supremacy.