With fuel starting to thin out, Harvick's pace fell as he worked to keep Hamlin behind, beating the Joe Gibbs Racing driver to the line by 1.054s.
Pole-sitter Brad Keselowski brought out the first unscheduled Caution near the end of Stage 2, spinning at Turn 4 on Lap 117.
Aric Almirola (Stewart Haas Racing) and Richard Childress Racing team-mates Austin Dillon and Daniel Hemric all made contact as the front-runners took the green/white chequered flag for Stage 2.
The trio touched on the front stretch as Almirola and Hemric scraped their cars along the outside wall, while Dillon kept off the pit wall when he speared into the infield.
Kurt Busch held the lead for the start of Stage 3 but was quickly passed by Logano before two consecutive Caution periods briefly halted proceedings.
Cup Series debutant Spencer Boyd (Rick Ware Racing) brought out the Caution flag on Lap 134 after colliding with the wall at Turn 4 before Clint Bowyer (Stewart-Haas Racing) lost control of his car at Turn 3 after the restart.
Logano continued to hold the lead as Ricky Stenhouse Jnr (Roush Fenway Racing) brought out the final Caution of the race after suffering a punctured tyre and spin at Turn 4.
All cars on the lead lap chose to pit with Team Penske's Ryan Blaney becoming the new race leader after a fuel-only stop.
His team-mate Logano would quickly fight back for the lead on the restart, making the better jump with fresher tyres to run side-by-side.
Harvick soon reeled in second position on Lap 173 as he started his attack on Logano's lead with 27 laps to go.
Harvick's race-winning move came on Lap 183, passing Logano out of Turn 4.
A gap at the front then started to open as front-runners Keselowski and Logano were forced to pit for fuel on Laps 189 and 197 respectively.
Hamlin emerged in second, almost chasing down Harvick as he came up one second short of the victory.
Kyle Busch's series lead is now 20 points the Joe Gibbs Racing driver finished sixth and Logano, his nearest rival, 17th.
There are three rounds remaining until the Playoffs, the next of which is the Bristol Night Race on August 16-17 (local time).