Earnhardt restarted the race second after that caution, but lost the spot to Johnson on the restart. A few laps later, Keselowski also passed Earnhardt to take third.
The eighth caution of the race, which came out with three laps to go, sent the race into overtime, or a green-white-checker-finish, leaving several cars having to worry about fuel.
When the race restarted for two-lap sprint to the finish, the front-runners had enough fuel to get to the checkered flag.
Edwards pulled away on the final lap, as Johnson and Hamlin battled side-by-side for second.
"I didn't have much all day. (Crew chief) Darian (Grubb) and the pit crew carried us," Hamlin said. "We overachieved today, and that's what you have to do when you don't have a good car."
Finishing sixth through 10th were Clint Bowyer in the No. 15 Michael Waltrip Racing Toyota, Kenseth, Tony Stewart in the No. 14 Stewart-Haas Racing Chevrolet, the No. 24 Hendrick Motorsports Chevrolet of Jeff Gordon and Jeff Burton in the No. 31 Richard Childress Racing Chevrolet
NOTES: Edwards' 70-race winless streak tied his longest career-winless streak, which was also snapped at Phoenix in 2010. ... The win at Phoenix was the 20th-career win for Edwards. ... Edwards is the only repeat winner in the last nine races at Phoenix. ... Prior to the Phoenix race, Edwards hadn't led in a Sprint Cup race since August 2012 at Bristol (Ten.) Motor Speedway. ... Hamlin's crew chief, Darian Grubb, has top-five finishes in all four races so far on Phoenix's new track configuration.