Fernandez gave up five runs in five innings and fell to 26-2 at Marlins Park.
Miami's Dee Gordon, the 2015 NL batting and stolen bases champion, returned from an 80-game suspension for failing a drug test and went 0 for 4. Ichiro Suzuki doubled as a pinch hitter in the seventh for Miami and needs two hits for 3,000.
Diaz and Matt Holliday homered in the third inning against Fernandez (12-5), who had never previously given up more than one homer in a home game. His only other loss at Marlins Park came on opening day this year against Detroit.
Michael Wacha (6-7) allowed three runs in six innings, and three relievers completed an eight-hitter. Seung Hwan Oh pitched around a one-out single in the ninth for his seventh save.