BRADENTON, Fla. — A.J. Burnett had little trouble the first time through Boston’s batting order. The second time around was different.

Burnett left with runners on in the third inning, David Ortiz and Pablo Sandoval followed with home runs off Ryan Beckman that erased a deficit, and the Red Sox beat the Pittsburgh Pirates 5-1 on Thursday.

After starting with two hitless innings, Burnett walked Blake Swihart and Shane Victorino opening the third. Dustin Pedroia flied out and Beckman relieved.

As Burnett walked off the mound, the 38-year-old right-hander looked at Ortiz and shrugged.

“Did they take me out because you’re up?” he asked.

Ortiz, a .295 career hitter against Burnett, smiled and stepped back into the box.

He took two strikes from Beckman, a young right-hander with no experience above Double-A, and drove the third pitch over the center-field wall for a 3-1 lead.

Hanley Ramirez lined out, and Sandoval homered to center, his first home run in a Red Sox uniform.

Burnett walled three and struck out two in 2 1/3 hitless innings.

“You tell yourself it doesn’t matter who is in the box,” Burnett said. “You get ready for a righty or lefty, doesn’t matter if it’s David or Victorino, (Mike) Napoli or Pedroia. But deep down it matters. I faced those guys when I was in New York and Toronto, and it was fun to go up against them again.”

Pirates closer Mark Melancon allowed two hits and a run in an inning, giving up an RBI double to Victorino that boosted Boston’s lead to 5-1 in the fourth.

Sandoval, who signed a $95 million, five-year contract during the offseason, went 2 for 3.

OFFENSE SPUTTERING

Since scoring eight runs in their spring training opener March 3 against Toronto, the Pirates have scored 15 runs in 10 games. “It gives talk radio something great to work with,” Pittsburgh Manager Clint Hurdle said. “The lineups are mixed and matched. We’re going to continue to work on being the offense we know we can be.”

STARTING TIME

PIRATES: Burnett’s emphasis was on his change-up, a pitch he admits he’s been “stubborn” about throwing during his major league career. “Hopefully I can get over it before I retire,” he said. He induced four ground balls and two fly balls.

RED SOX: Right-hander Clay Buchholz survived a rocky first inning that included two singles, a hit batter, a wild pitch, a wild pickoff and a sacrifice fly. He allowed four hits in three scoreless innings with two strikeouts.

DEAL DONE

The Red Sox finalized a minor league contract with 19-year-old Cuban infielder Yoan Moncada and will assign him to the team’s minor league camp at spring training.

The switch-hitting Moncada played two seasons for the top league in Cuba. He spent last year at second base.

Moncada’s agent and the Red Sox reached agreement in late February on a deal with a $31.5 million signing bonus. Moncada had to pass a physical before the contract was completed. The Red Sox will pay $63 million overall to get Moncada, due to a tax on international signings.