NEW YORK — David Ortiz homered twice, passing Hall of Famer Carl Yastrzemski for second place on Boston’s career list, and Steven Wright pitched a three-hitter as the Red Sox beat the New York Yankees 5-1 on Sunday night.

Wright (3-3) walked one and struck out seven, breezing to his first complete game in 17 major league starts. He was two strikes from a shutout when Brett Gardner homered with two outs in the ninth inning.

The right-hander hardly got rattled, whiffing pinch-hitter Ronald Torreyes with his 101st pitch to end it.

Mixing his 73-75 mph knuckleballs with an occasional 87 mph fastball, Wright baffled the Yankees all night. When he threw something soft, they seemed to hit it even softer. When he dialed up a heater, they swung late and missed.

Dustin Pedroia hit an early two-run homer and Xander Bogaerts also went deep for the Red Sox, who prevented a three-game sweep and won for the fourth time in six meetings with their longtime rivals this year.

In his farewell season, the 40-year-old Ortiz has five home runs against the Yankees since April 29. He connected for two long solo shots off struggling Yankees starter Luis Severino (0-5).

Ortiz has hit 454 of his 512 career homers with the Red Sox, moving him ahead of Yastrzemski (452) and leaving the slugger behind only Ted Williams (521).

Severino matched a career high with nine strikeouts in 62/3 innings, but he gave up three home runs.

TRAINER’S ROOM

RED SOX: Left-hander Eduardo Rodriguez (right knee) threw 93 pitches in his third rehab start for Triple-A Pawtucket. He gave up three earned runs and six hits, including two homers, over 52/3 innings against Rochester. Boston Manager John Farrell said the team will meet with Rodriguez on Monday at Fenway Park, and the pitcher’s next start could be in the majors. “I wouldn’t rule it out,” Farrell said. … Right-hander Joe Kelly (shoulder impingement) is scheduled to make his second rehab start Wednesday for Pawtucket. “We’ll look to advance him to 80-85 pitches,” Farrell said. … Right-hander Sean O’Sullivan, called up from Pawtucket on Friday, is likely to make a spot start Tuesday night against Oakland, Farrell said.

YANKEES: Center fielder Jacoby Ellsbury missed his second straight game after straining a hip muscle Friday night and probably won’t be ready to play Monday night, Manager Joe Girardi said.