They didn't make it easy on themselves, but the Red Sox walked off with a 5-4 win over the Blue Jays in the finale of their four-game set at Fenway Park.

Koji Uehara, who had recorded saves in three consecutive appearances, recorded his first blown save of the season in the top of the ninth inning after giving up a game-tying solo home run to Jose Bautista. It was the 13th blown save recorded by Sox relievers this season, matching the Indians for fifth-most in the majors, behind the Orioles who lead with 16.

Uehara got the win, though, as the Sox pulled out their seventh walk-off win of the season.

With one out in the bottom of the ninth, Brandon Snyder singled off of Juan Perez and Jacoby Ellsbury walked, ending Perez’s outing. Shane Victorino needed just two pitches from Casey Janssen to give the Sox the win as his grounder went through the legs of Jays first baseman Josh Thole.

It was the first walk-off win for the Sox on an error since Aug. 1, 2010, against the Tigers.

Ryan Dempster went 5 1/3 innings, giving up two runs on seven hits and three walks with two strikeouts. His ERA improved to 4.11.

Left-hander Mark Buehrle started for the Jays and went six innings, giving up four runs on seven hits and a walk with four strikeouts.

The Red Sox got three runs off Buehrle in the second, sending eight batters to the plate. Mike Napoli and Daniel Nava led off with back-to-back singles. Ryan Lavarnway reached on a ground-rule double, scoring Napoli. After Jose Iglesias struck out, Snyder’s double scored Nava and Lavarnway. It was Snyder’s first hit as a member of the Red Sox.

The Jays got two runs off Dempster in the fourth. Edwin Encarnacion led off with a single, going to second on Rajai Davis’ one-out base hit. Colby Rasmus’ single to right scored Encarnacion, with Davis going to second. With JP Arencibia batting, Davis stole third without drawing a throw from catcher Ryan Lavarnway. It was his fifth stolen base of the series and 19th of the season. Arencibia walked to load the bases, and Davis scored on Maicer Izturis’ fielder’s choice.

The Sox added a run in the fifth when Jacoby Ellsbury led off with a single to left, scoring on Jonny Gomes’ two-out double, giving the Sox a 4-2 lead.

The Jays threatened in the sixth, loading the bases with no outs. After Dempster got Arencibia to pop out, his outing was done, with left-hander Craig Breslow relieving him. Breslow got Izturis to pop out and pinch-hitter Emilio Bonifacio struck out.