BOSTON — John Lackey had just struggled to make it through the sixth inning Tuesday night when Victor Martinez offered him some encouragement.

“He told me to hang in there and he was going to take care of me,” Lackey said. “He did. It was pretty cool.”

Martinez had four doubles and five hits in all, driving in the go-ahead run after Oakland walked the bases loaded in the sixth inning, and the Red Sox rallied from a four-run deficit to beat the Athletics, 9-4.

The five hits matched a career high for Martinez, and the four doubles tied a major-league record matched only three other times by a catcher since 1952.

“It’s not that I had a feeling but we just never quit,” said Martinez, who was batting .227 on May 18 but has had multiple hits six times in nine games since then. “I’ve been in a big hole since the start of the season. But I never lost my confidence.”

Lackey (6-3) spotted the A’s to a 4-0 lead before Adrian Beltre hit a three-run homer in the fifth. In the sixth, Bill Hall reached on a leadoff walk, then Darnell McDonald and Marco Scutaro both tried to sacrifice but also wound up walking.

Hall scored to tie it on Dustin Pedroia’s double-play grounder, then Martinez’s line drive one-hopped into the stands to make it 5-4. Hall added an RBI triple in the seventh, and Martinez also hit an RBI double and scored in the eighth, when the Red Sox added three runs to make it 9-4.

“We dug ourselves a little bit of a hole and didn’t panic, didn’t get frustrated,” Red Sox Manager Terry Francona said. “Beltre’s hit was huge. Lackey … you look at numbers, and we certainly do, but I don’t think you can measure the way a guy almost wills himself, the way he competes, to give us a chance to win.”

Lackey gave up four runs on 12 hits and four walks, striking out two, but the Red Sox won their third straight and for the eighth time in 10 games.

“We did have a nice little lead going against Lackey,” A’s Manager Bob Geren said. “I thought we had a real good offensive approach, got some big hits.”

Gabe Gross had three hits for the A’s, who had won five of their previous six games. Tyson Ross (1-4) inherited a 4-3 lead when he relieved Gio Gonzalez at the start of the sixth, walking two before Craig Breslow came in.

Pedroia doubled in the eighth to snap an 0-for-17 slump, then scored on Martinez’s fourth double of the game. Kevin Youkilis and J.D. Drew added RBI singles to make it 9-4.

Daric Barton hit a two-run homer for Oakland in the third. The A’s made it 4-0 when Ryan Sweeney doubled and scored on Jack Cust’s single, then Cust scored on Mark Ellis’ bloop double to right.

But the Red Sox got back in the game in the fifth.

After Martinez doubled off the Green Monster and Youkilis singled off third baseman Kevin Kouzmanoff’s glove, Beltre smacked the ball so hard off the Monster Seats that it bounced much of the way back toward the infield.