Jhonny Peralta delivered against a closer who’s having as many problems as the Detroit Tigers’ bullpen.

Peralta walloped a two-run homer with none out in the ninth off Andrew Bailey to give the Tigers a 4-3 comeback win over the Boston Red Sox at Comerica Park on Thursday night.

Peralta’s third career walk-off homer produced the Tigers’ first walk-off win of the season and overcame the go-ahead, eighth-inning run allowed by Phil Coke. The left-hander walked the first two Boston hitters of the inning on four pitches apiece, then allowed the tie-breaking single to David Ortiz, who’d had one hit in 15 career at-bats off him.

Bailey arrived for the ninth. Victor Martinez led off with a walk. Peralta fell behind 0-2, checked his swing on a high 1-2 pitch, then lofted the right-hander’s next delivery over the fence in left.

“The same thing that happened to Coke is the same thing that happened to them in the ninth – walk the leadoff guy with a one-run lead,” Tigers manager Jim Leyland said. “That was a backbreaker.”

In Bailey’s last five outings, he has allowed four homers and blown three saves. So the Tigers aren’t the only first-place team lately with a closer plagued by homers.

Drew Smyly earned this win. He got out of Coke’s two-on, none-out jam in the eighth and threw a scoreless ninth. “Terrific,” Leyland said.

In the Tigers’ last two wins, Smyly has thrown five scoreless innings and recorded a save and a win. He has provided stability in a bullpen that was on the verge of dropping to 4-14 this season until Peralta unloaded.