The score was tied 1-1 in the fifth when Marco Scutaro reached on a one-out single against Wade Miley (15-10).
After Pablo Sandoval flew out, Posey (3-for-4) sliced a 2-0 pitch over the right-field fence, putting San Francisco ahead for good.
Angel Pagan collected his 13th triple, breaking Willie Mays' club record for three-baggers in a single season.
Zito (12-8) allowed only one run on six hits over 6 2/3 innings, stretching his unbeaten streak to eight starts. The left-hander issued one walk and struck out four.
Miley ended up allowing three runs on eight hits over seven full frames.
Justin Upton homered for the Diamondbacks.
Notable deaths of 2014 [PHOTOS]