San Francisco received right-handed pitching prospects Shaun Anderson and Gregory Santos.
Nunez had a two-run double and scored two runs in three plate appearances Tuesday being replaced by Kelby Tomlinson in the fifth inning, giving him a .308 average with four home runs and 31 RBIs in 76 games for the Giants this season.
The 30-year-old was acquired by the Giants last July 28 from the Minnesota Twins for left-handed pitcher Adalberto Mejia.
Nunez is owed approximately $1.5 million for the rest of the year. He will be a free agent after the season.
Anderson, 22, went 6-3 with a 3.42 ERA in 18 starts with high Class A Greenville and low Class A Salem this season. He was drafted by Boston in the third round in 2016 out of the University of Florida.
Santos, 17, was signed by the Red Sox as an international free agent in 2015. He went a combined 5-3 with a 2.79 ERA over the last two seasons in the rookie-level Dominican Summer League.