BOSTON — If the Tuesday night game between the Boston Red Sox and San Francisco Giants served as a World Series preview, baseball fans are in for quite a treat.

On a night that featured big hits, stellar defense and an raucous crowd for a game between two of the game’s best teams, the Red Sox emerged the victors.

Hanley Ramirez launched a trio of three-run homers and made a series of outstanding defensive plays to lead Boston past San Francisco 11-7 at a sold-out Fenway Park. The result moved the Red Sox into first place in the American League East, a half-game ahead of the Baltimore Orioles.

The crowd was decidedly split. Plenty of Giants fans were on hand, engaging in back-and-forth chants with the hometown fans all night, giving the contest an October feel.

“I thought the crowd the last two nights had a definite different feel,” Red Sox manager John Farrell said. “(The Giants) had a great following here. There was a lot of electricity in the ballpark. They saw two very good baseball games.”

Boston blanked San Francisco 4-0 in the series opener Tuesday, with Fenway Park drawing its highest attendance figures of the season on back-to-back nights.

On Wednesday, Ramirez enjoyed his first career three-homer game, and he also made a series of key defensive plays at first base. He had a chance to hit a major-league-record-tying fourth homer in the eighth inning, but he grounded out to the pitcher.

Ramirez tipped his cap to crowd as he received a standing ovation walking back to the dugout.

“That’s Sox Nation,” said Ramirez, who had a career-high six RBIs. “They know that I’m working hard every day and giving everything that I’ve got on the field, and it’s what I’m supposed to do.”

Drew Pomeranz didn’t factor into the decision in his Red Sox debut, hanging zeros through three innings before imploding in a five-run Giants fourth.

The All-Star lefthander lasted just three-plus innings, giving up five runs on eight hits with two strikeouts.

Pomeranz was acquired from the San Diego Padres last Thursday. He was scheduled to face San Francisco at Petco Park last Sunday before the trade.

“I faced these guys four times this year,” Pomeranz said. “I was going along pretty good there through the first three (innings). I made some bad fastball-location pitches, and they made me pay for it.”

Matt Barnes (3-3) earned the win with three scoreless innings of relief.

Sandy Leon hit a solo home run and an RBI triple as Boston (53-39) improved to a season-best 14 games over .500 with its sixth consecutive win at Fenway. The Red Sox are 11-3 in July after sweeping the two-game series.

Giants starter Matt Cain (1-6) struggled in his return from the disabled list, getting the hook after 2 1/3 innings. He was charged with five runs on six hits and a walk while striking out one.

“I had a lot of positives,” said Cain, who pitched for San Francisco for the first time since June 13. “I had some breaking balls I threw pretty good and some fastballs I threw pretty good.”

Mac Williamson launched a three-run homer and Trevor Brown had a two-run blast for the Giants (57-38), who lost their fifth straight out of the All-Star break.

Brown finished with three hits, as did Boston’s Mookie Betts. Boston out-hit San Francisco 16-15.

Ramirez clocked his first homer into the Red Sox’s bullpen with no outs in the second, and Travis Shaw clubbed a home run to right two at-bats later.

Ramirez’s second shot into the center field bleachers sparked a five-run third for Boston, which included Leon legging out his first career triple in 276 at-bats.

Pomeranz unraveled in the fourth as Williamson struck his bomb to right-center and Brown bounced a first-pitch homer over the Green Monster in left.

San Francisco’s Ramiro Pena and Denard Span had RBI singles in the fifth to make it a one-run game.

“I can’t say enough about how these guys battled,” Giants manager Bruce Bochy said. “We get down eight runs and have the tying run come to the plate the next inning. Hard-fought game.”

Boston shortstop Xander Bogaerts gave fans a scare after Pena’s throw from third to first hit him in the helmet while running out his fourth-inning single. Bogaerts slammed his helmet down and was checked out by trainers, but he stayed in the game.

Tensions rose in the bottom of the fourth as Giants reliever Albert Suarez hit Ramirez with a pitch in his left elbow.

Ramirez stared down Suarez as he walked to first, and plate umpire Stu Scheurwater warned both dugouts.

“Every time I get hit, that fires me up,” Ramirez said.