Earnhardt had the checkered flag in his sights as he came around turn four on the final lap at Charlotte Motor Speedway with the lead and seemed about to end his 104-race victory drought.
But just then his National Guard Chevy began slowing down, and Harvick, who had swept around the outside to avoid a tangle between two cars, shot past him with a half-mile to go to grab the win.
Earnhardt had forged into the lead two laps earlier when Kasey Kahne ran out of fuel following the 14th caution of the race, seemingly opening the door for Earnhardt to end his frustration streak.
A slight miscalculation on his fuel, however, cost him the win.
David Ragan, Joey Logano and Kurt Busch rounded out the Top 5 finishers.