ST. PETERSBURG, Fla. — The scenario made a lot of sense to Boston manager John Farrell. It made a lot of sense to Rays manager Joe Maddon, too.

But ultimately, Burke Badenhop’s sinker didn’t sink and Matt Joyce ruined the whole thing.

Joyce singled home the game-winner with the bases loaded in the bottom of the 10th inning on Monday as the Tampa Bay Rays beat the Boston Red Sox 4-3 to split a four-game series.

“For me, I was just trying to see the ball up,” said Joyce who was 1-for-5 with two strikeouts. “That was the biggest thing; hit the ball to left field.”

It worked. Left fielder Yoenis Cespedes made a quick move back, shook his head, and began jogging toward the dugout as Boston suffered its ninth walk-off loss of the season and third against Tampa Bay.

Catcher Ryan Hanigan went 2-for-4. He led off the 10th inning with double to left against Badenhop (0-3) that was upheld after a video review.

Center fielder Kevin Kiermaier, a left-handed hitter, was then walked intentionally so Badenhop could face Ben Zobrist. The second baseman advanced both runners with a bunt to bring up right fielder Wil Myers, who was walked intentionally to load the bases.

Against a drawn-in defense, Joyce turned the first pitch he saw into his 51st RBI of the season.

“He had a tough night to that point,” said Maddon, who liked Joyce’s prospects as a fly-ball hitter. “But Badenhop right there I thought was a pretty good matchup. That’s a tough moment to be in because Badenhop throws so many ground balls.”

Cespedes’ two-out single off just-promoted right-hander Steve Geltz had tied the game 3-3 in the eighth inning. Rookie Mookie Betts scored from second on bounder through the hole. Betts had singled and moved to second on a fielder’s choice against Jeff Beliveau.

It was Cespedes’ 90th RBI of the season overall was his 23rd since being acquired from Oakland on Aug. 1.

Tampa Bay improved to 67-71. Boston fell to 61-77.

Right-hander Grant Balfour improved to 2-6 after working a scoreless tenth.

Rays starter Drew Smyly had left with a 3-2 lead in the sixth after allowing two runs on three hits and two walks with seven strikeouts in 5 2/3 innings.

The left-hander, acquired from Detroit as part of a trade for former Cy Young Award winner David Price, had worked at least seven innings in four consecutive starts

Red Sox counterpart Rubby De La Rosa allowed three runs on six hits with four strikeouts in 5 1/3 innings.

Boston took a 1-0 lead in the third on Betts’ RBI single to center. Catcher Christian Vazquez had begun the rally innocently enough with a two-out walk, but hustled home when Betts ripped a Smyly pitch to the wall for his ninth RBI since being recalled from Triple-A on Aug. 19.

Tampa Bay responded with a three-run third, powered by third baseman Evan Longoria’s two-run single.

Boston got a run in the top of the fourth on designated hitter Mike Napoli’s 17th homer of the season.

NOTES: Boston is not expected to call up players until the season ends for Pawtucket, which clinched an International League wild-card spot Sunday. Likely promotions include highly touted OF Jackie Bradley Jr., who struggled beginning the season with the Red Sox and Cuban OF Rusney Castillo, who signed a seven-year, $72.5 million deal last week. Castillo went 1-for-3 with a walk on Sunday in a Gulf Coast League game before being assigned to Double-A Portland. … Tampa Bay activated OF David DeJesus (left hand fracture) from the disabled list. … Red Sox 2B Dustin Pedroia sat out again Monday as he works through MLB concussion protocols. Dizzy after being elbowed in the head attempting to tag out a runner Saturday, he will have to complete set stages, including an evaluation by a concussion specialist. … Rays CF Desmond Jennings sat out a third straight day recovering from left knee soreness. Kevin Kiermaier again replaced him in center field but 2B Ben Zobrist took his leadoff slot. … The Rays went errorless for the first time in nine games.