Joe Gibbs Racing's Hamlin was leading throughout a large portion of the final stage before Kyle Larson hit the wall at Turn 1 and triggered a caution with 37 of the 301 laps to go.
Harvick was running in the top five and opted to stay out in order to take the lead at the restart.
The gap between the two had stabalised at half a second, but with Harvick compromised by traffic on the penultimate lap, Hamlin closed to within inches of the SHR Ford entering the last tour.
Hamlin tagged Harvick's bumper entering Turn 1 but the SHR driver managed to stay ahead.
Entering the final turns, Harvick took a defensive line and despite closing to Harvick's outside quarter-panel at the last corner, Hamlin was unable to squeeze through.
Harvick's first win of 2019 arrives at the same venue at which he clinched his sixth victory last season. It is also the first win of the year for SHR.
Starting at the back of the field in a backup car - and the same JGR Toyota which propelled Truex Jr to victory at Richmond earlier in the season - Hamlin rose to ninth by the end of stage one.
Both Hamlin and Harvick were among a number of front runners to sacrifice stage points at the end of the second stage, pitting at a late caution in order to gain track position towards the end of the race.
Erik Jones clinched a second consecutive third place. He endured an eventful second stage, trading paint with Hamlin at the two battled early on before Jones collided with Alex Bowman's Chevrolet in the pitlane.
Jones slipped to 28th as a result, and while recovering he tagged the Roush Fenway Racing Ford of Ricky Stenhouse Jr, causing a tyre rub which would send the #17 car into the wall.
Jones surged back through the pack in stage three and opted to run the same strategy as Harvick at the final caution, narrowly avoiding crossing the commitment line for the pitlane after a late call to stay out.
A late charge from Leavine Family Racing's Matt DiBenedetto propelled him to his second top five finish of the year, behind the top Penske car of Ryan Blaney.
Martin Truex Jr took sixth ahead of Ryan Newman. The latter ended up seventh despite starting in a backup car at the tail of the field and losing a cylinder halfway through the final stage.
His Roush Fenway crew managed to change the faulty coil wire through three consecutive pitstops under caution to stay on the lead lap.
Kyle Busch made sure all four Joe Gibbs Racing cars reached the top eight.
He claimed victory in stage one but contact with Larson late in stage two triggered an additional pitstop compromised his strategy.
Later hitting the Turn 1 wall, Busch drove through tow misalignment to eighth.
Points' leader Joey Logano and his Penske team-mate rounded out the top 10, while stage two winner Aric Almirola took 11th in his 300th NASCAR start.
|1||Kevin Harvick||Stewart-Haas Racing||Ford||301||3h03m37.s|
|2||Denny Hamlin||Joe Gibbs Racing||Toyota||301||0.210s|
|3||Erik Jones||Joe Gibbs Racing||Toyota||301||3.987s|
|4||Ryan Blaney||Team Penske||Ford||301||5.447s|
|5||Matt DiBenedetto||Leavine Family Racing||Toyota||301||5.939s|
|6||Martin Truex Jr.||Joe Gibbs Racing||Toyota||301||6.406s|
|7||Ryan Newman||Roush Fenway Racing||Ford||301||8.504s|
|8||Kyle Busch||Joe Gibbs Racing||Toyota||301||8.997s|
|9||Joey Logano||Team Penske||Ford||301||10.944s|
|10||Brad Keselowski||Team Penske||Ford||301||11.566s|
|11||Aric Almirola||Stewart-Haas Racing||Ford||301||12.898s|
|12||William Byron||Hendrick Motorsports||Chevrolet||301||13.280s|
|13||Paul Menard||Wood Brothers Racing||Ford||301||14.095s|
|14||Alex Bowman||Hendrick Motorsports||Chevrolet||301||14.992s|
|15||Chris Buescher||JTG Daugherty Racing||Chevrolet||301||16.475s|
|16||Ty Dillon||Germain Racing||Chevrolet||301||17.023s|
|17||Michael McDowell||Front Row Motorsports||Ford||301||19.588s|
|18||Kurt Busch||Chip Ganassi Racing||Chevrolet||301||21.920s|
|19||Daniel Suarez||Stewart-Haas Racing||Ford||300||1 Lap|
|20||Clint Bowyer||Stewart-Haas Racing||Ford||300||1 Lap|
|21||Ryan Preece||JTG Daugherty Racing||Chevrolet||300||1 Lap|
|22||Darrell Wallace Jr.||Richard Petty Motorsports||Chevrolet||300||1 Lap|
|23||Corey LaJoie||Go FAS Racing||Ford||299||2 Laps|
|24||Matt Tifft||Front Row Motorsports||Ford||299||2 Laps|
|25||Ross Chastain||Premium Motorsports||Chevrolet||299||2 Laps|
|26||Landon Cassill||StarCom Racing||Chevrolet||298||3 Laps|
|27||Reed Sorenson||Premium Motorsports||Chevrolet||294||7 Laps|
|28||Andy Seuss||Petty Ware Racing||Ford||291||10 Laps|
|29||Chase Elliott||Hendrick Motorsports||Chevrolet||290||11 Laps|
|30||Jimmie Johnson||Hendrick Motorsports||Chevrolet||288||13 Laps|
|31||Quin Houff||Spire Motorsports||Chevrolet||287||14 Laps|
|32||Austin Dillon||Richard Childress Racing||Chevrolet||268||33 Laps|
|33||Kyle Larson||Chip Ganassi Racing||Chevrolet||264||Accident|
|34||David Ragan||Front Row Motorsports||Ford||261||40 Laps|
|35||Austin Theriault||Rick Ware Racing||Chevrolet||185||Rear Gear|
|36||Ricky Stenhouse Jr.||Roush Fenway Racing||Ford||135||Accident|
|37||Daniel Hemric||Richard Childress Racing||Chevrolet||110||Accident|
Get unlimited access to the world’s best motorsport journalism with Autosport Plus