Denny Hamlin earned his first Martinsville victory in a decade, dominating with a race-high 274 laps in the lead.