BOSTON – Alex Rodriguez was hit by a Ryan Dempster fastball in his first at-bat, then homered to start a four-run sixth inning that carried the New York Yankees to a 9-6 win over the Boston Red Sox on Sunday night.

Yankees Manager Joe Girardi was ejected after coming out of the dugout and hollering at plate umpire Brian O’Nora, who had warned both benches immediately after Rodriguez was hit by Dempster. The 3-0 pitch hit Rodriguez as he led off the second inning. It struck his left elbow pad and ricocheted off his back.

Players streamed from the dugouts and benches of the longtime rivals, but no skirmishes developed.

The incident seemed to spark the Yankees, who were trailing 2-0 at the time.

Rodriguez, who went 3 for 4 with two runs and two RBI, was suspended recently for 211 games by Major League Baseball in the Biogenesis drug case. He appealed the penalty and can play until there is a final decision.

Boston’s lead in the AL East was cut to one game over Tampa Bay. The game took 4 hours, 12 minutes.

One Yankee drew loud cheers from the Fenway Park crowd. Mariano Rivera received a standing ovation as he ran in from the bullpen for the ninth. In his first appearance since blowing his third straight save a week earlier, he got his 36th save in 41 opportunities when Jonny Gomes lined out to left with two runners on.

CC Sabathia (11-10) got the win despite allowing six runs in 51/3 innings.

Booed every time he came to bat — and even when he was on deck in the first inning — Rodriguez drew more jeers after he led off the sixth with a homer off Dempster (6-9) to cut Boston’s lead to 6-4.

As Rodriguez’s second homer of the year landed in the center-field bleachers, he clapped his hands and let out a shout at first base. Then he clapped again and pointed both hands skyward as he crossed home plate.

He continued to the dugout where he was congratulated by teammates. The homer was the 649th of Rodriguez’s career, 11 behind Willie Mays for fourth place on the career list.

Dempster left later in the inning with the bases loaded, and Brett Gardner hit a three-run triple off reliever Drake Britton to put the Yankees ahead 7-6.

Rodriguez was one of four Yankees hit by pitches, but his was the only one that appeared to be intentional.

Dempster’s first pitch went behind Rodriguez’s knees as fans chanted “You’re a cheater!” The next two pitches were inside before the fourth pitch struck Rodriguez. He walked slowly to first base, accompanied by a trainer and staring at Dempster but not making a move toward the mound.

Boston had taken a 2-0 lead in the first on a sacrifice fly by Gomes and an RBI single by Jarrod Saltalamacchia. New York tied it in the second. Rodriguez took third on a double by Curtis Granderson and scored on a single by Nunez, and Overbay followed with a sacrifice fly.

Rodriguez’s run-scoring groundout gave the Yankees a 3-2 lead in the third before the Red Sox tied it in the bottom of the inning on an RBI groundout by David Ortiz.

The Red Sox took a 5-3 lead in the fourth on Stephen Drew’s sacrifice fly and Will Middlebrooks’ 10th homer. A bases-loaded walk to Daniel Nava boosted the lead to 6-3 in the fifth.