Peavy (9-4), obtained from the Chicago White Sox Wednesday in a trade-deadline deal, turned in a strong performance in his first game with Boston, limiting the Diamondbacks to two runs on four hits.
The veteran right-hander walked two and struck out seven.
Koji Uehara racked up his 10th save as the Red Sox evened their three-game interleague set and maintained a one-game lead over Tampa Bay atop the American League East.
The score was tied 1-1 until the seventh inning when the Bosox put Stephen Drew at third and Brock Holt at second with none out against Arizona starter Patrick Corbin, and Jacoby Ellsbury blooped an RBI single for the go-ahead run.
Corbin (12-3) was saddled with the loss after surrendering three runs on eight hits in six innings.
Paul Goldschmidt homered for the D-backs, who fell 4 1/2 games behind the NL West-leading Los Angeles Dodgers.