PHOENIX, Ariz. — Red Sox manager Alex Cora chose Colten Brewer to pitch the ninth inning even though Matt Barnes, his best reliever, still was available.

Barnes has allowed one hit and no walks while striking out four in 2.1 scoreless innings so far. Brewer entered having allowed one hit and four walks while striking out six in 3.2 scoreless innings.

“Where they were in the lineup. The way he (Brewer) has been throwing the ball. We liked him there," Cora said. "We thought the matchups were good for us. It just didn’t work out.”

The Red Sox lost 5-4 to the Diamondbacks here at Chase Field.

Brewer entered with the fifth, sixth and seventh spots in the Diamondbacks batting order due. Alex Avila pinch hit in the fifth spot, which had become the pitchers’ spot. Brewer struck out Avila.

Eduardo Escobar followed with a single to right field and reached second on Christian Vazquez’s passed ball.

Nick Ahmed, an East Longmeadow High grad, singled to right. But Mookie Betts threw out Escobar at the plate for the second out.

With Ahmed at second base and two outs, Carson Kelly ripped a walkoff single to left field against Brewer.

“I was basically just trying to get a groundball and get out of the inning," Brewer said about the Kelly at-bat. “Maybe weak contact, maybe a swing-and-miss. But he ended up shooting it to left field.”