The 30-year-old has been with the Giants since being traded to the club last season.
In return, Boston will send right-handed pitching prospects Shaun Anderson and Gregory Santos to San Francisco.
The Red Sox hope Nunez, who is batting .308 with four home runs and 31 RBIs and has 18 steals this season, will help fill the hole they have had all season at third base.
Third baseman Pablo Sandoval, who the Red Sox signed away from the Giants with a three-year, $95 million deal in 2014, was released by Boston last week. Coincidentally, Sandoval, upon his release, signed a minor league contract to go back to San Francisco.
The Giants, who entered Tuesday night’s play 31½ games back of the National League West-leading Los Angeles Dodgers, also are open to trade discussions involving pitchers Johnny Cueto and Jeff Samardzija, according to ESPN’s Buster Olney.
Nunez had been on a tear for the Giants. His .348 average is the fourth highest in the majors since June 1 (minimum 100 plate appearances). He went 9-for-16 (.563) in his final four games with San Francisco.
Nunez was seen hugging teammates in the Giants’ dugout after getting pulled from Tuesday’s contest.
In addition to third base, Nunez has played four other positions in his career (second base, shortstop, left field and right field) and has a negative defensive runs saved at all five spots.
News of the deal was first reported by Fox Sports.