“We needed that. We’ve been having a lack of offense,” David Ortiz said after he and first baseman Mike Napoli hit back-to-back home runs in the 10th inning — just Boston’s second and third hits of the game — to give the Red Sox a 2-1 victory and a sweep of a low-scoring three-game series on Wednesday.

“We haven’t been able to produce for our pitching,” said Ortiz. “Our pitching has been outstanding lately — we just haven’t been able to hit.”

The Red Sox scored five runs in the three games. They have scored nine in the last five, going 2-for-30 with runners in scoring position.

They were facing a 1-0 loss when, with Minnesota closer Glen Perkins unavailable because of a back problem, Ortiz hit his 16th and Napoli his seventh, both off right-hander Casey Fien (3-4).

Ortiz, the designated hitter who spent the end of the seventh inning screaming up at the official scorer over a scoring decision, ripped one down the line in right.

Napoli went to dead center field — all this after Twins right fielder Chris Parmelee homered off closer Koji Uehara (2-1) in the top of the inning. It was Parmelee’s fourth homer of the year, his third against Boston, one a walk-off in Minneapolis.

The homers ended a day that saw Boston’s John Lackey pitch nine shutout innings, while Twins right-hander Kyle Gibson gave up one hit over seven.

“Our pitching’s been unbelievable, especially today,” said Napoli. “Lackey going nine shutout innings and we didn’t do anything. We got one hit. So it was nice — we picked up Koji and got a win and a series sweep. We’re just worried about winning any way we can.

“Today was a nice day for us. We got to try to keep it going and have a nice road trip.”

While the Red Sox (34-38) head for Oakland, the Twins (32-38) go home toting a four-game losing streak.

“It’s the worst feeling in the world,” said Fien. “When you’ve got a pitching staff that threw like that and then they ask me to come up big and do my part … you come out with the L. It’s not a good feeling.”

The Red Sox swept by scores of 1-0, 2-1 and 2-1.

Parmelee, who had two earlier singles, connected to end a 21-inning scoreless streak for Uehara.

Lackey, turning in his third no-run performance in his last six starts, gave up only the singles to Parmalee through the first seven innings. He yielded another hit in the eighth and a walk in the ninth. Only one runner reached scoring position.

Gibson, who has thrown 22 straight scoreless innings over his last three starts, retired the first 14 before left fielder Daniel Nava doubled with two out in the fifth. Gibson didn’t walk a batter and struck out eight.

“I tell you what, that kid that pitched for them today? Wow, very impressive,” said Ortiz. “For a young kid to have that sense of knowing what he’s doing and spotting his pitches the way he did, very impressive.”

With two out in the seventh, Ortiz reached on what he thought was a hit but official scorer Bob Ellis thought was an error on first baseman Joe Mauer.

After being erased on an inning-ending double play, Ortiz talked to an umpire and two teammates and pointed out to the scoreboard and couldn’t believe he didn’t get a hit.

He screamed up toward the press box, at Ellis, gave the scorer the thumbs down sign and then fired his helmet down the dugout steps.

He could be heard screaming about it in the shower and later said he felt like the home scorer should have been on his side. Official scorers work for Major League Baseball and not the teams.

“We tie the game. We win the game. It doesn’t get any better,” Ortiz said. “But I want my hit back.”

Ellis said after the game any thought he had of changing the call was overruled by the fact that it would have looked like he was “bullied” into it by Ortiz’s antics.