DETROIT — Jhonny Peralta’s ninth-inning homer gave the Detroit Tigers a joyful break from all that talk about their beleaguered bullpen.

It was Boston’s closer who lost this game, and now the Red Sox have some relief issues.

Peralta hit a two-run homer off Andrew Bailey in the bottom of the ninth Thursday night to give the Tigers a 4-3 victory.

Boston led 3-2 before Victor Martinez drew a leadoff walk off Bailey. Peralta followed with a line shot over the fence in left for his seventh homer of the year.

“I don’t try to hit a home run but I try to have good contact with the ball,” Peralta said. “That’s what happened when I had good contact.”

Detroit Manager Jim Leyland said before the game he was ready to use Joaquin Benoit to close instead of the struggling Jose Valverde, although he stopped short of naming Benoit as the long-term closer.

Red Sox Manager John Farrell said Bailey now will be given a break from closing.

“We’re going to back him out of there right now and try to get him fixed, so we’ll look at some other internal options to close,” Farrell said. “His velocity hasn’t come back since the DL stint and although he says he feels fine, the results obviously aren’t there.”

Bailey (3-1) missed time in May because of a bicep problem. Joel Hanrahan, Boston’s top choice to close, is out for the season after elbow surgery.

David Ortiz homered and drove in a tiebreaking run with an eighth-inning single to put Boston up, but Drew Smyly (3-0) replaced Phil Coke for Detroit and prevented any further scoring. He struck out four in two innings of relief.

Detroit improved to 2-19 when trailing after eight innings.

The Red Sox wasted a nice performance by John Lackey, who allowed two runs and seven hits in seven innings. Koji Uehara pitched a perfect eighth but Bailey didn’t get an out.

Jose Alvarez of Detroit allowed two runs and five hits in five innings in his second big league start, and Luke Putkonen got five straight outs in relief.

Then Leyland brought in Coke, the lefty who has struggled against right-handed hitters. Coke struck out the left-handed hitting Jacoby Ellsbury to end the Boston seventh, but walked switch-hitting Shane Victorino and right-handed hitting Dustin Pedroia to start the eighth.

The lefty-swinging Ortiz then pulled a base hit to right to give the Red Sox the lead.

Ortiz was 1 for 15 off Coke before that hit, which is why Leyland stuck with Coke.

“He didn’t do very good because he walked guys,” Leyland said. “He gets those two guys out, he probably gets Ortiz out. But he walked them and that’s a no-no.”

Peralta made up for that with one swing.

“I see everybody at home plate, it’s a good feeling, hitting a walk-off home run,” Peralta said. “It’s the best that I can feel.”

Smyly, one Detroit reliever who has been terrific, kept the deficit at one and gave the Tigers a decent chance at a comeback.

“It’s too late to score three or four runs. You’ve got to keep it where it’s at,” Smyly said. “I’m glad I was able to do that.”

Alvarez handled Boston’s lineup reasonably well, but Ortiz went deep in the fourth for his 15th homer of the season.