No telling if the face-to-face rancor helped. Who knows if the finger-in-the-face pointing changed anything. The hat-throwing, it's impossible to connect that with the clutch run-scoring.

But Rocco Baldelli on Wednesday tried a little fight-the-power passion, and the Twins finally beat the Red Sox. Related or not, both seemed to fire up a Target Field crowd that has watched plenty of frustrating losses lately.

In fact, the crowd of 23,912 shared Baldelli's in-your-face sentiment in the 10th inning, when replay failed to overturn what the Twins felt was an unjust out at first base. And what the heck, maybe that rage helped Kyle Farmer line a single to center three pitches later to deliver an emotional 5-4 victory for the Twins. Courtesy runner Willi Castro scored from third, and the Twins mobbed Farmer for delivering their sixth walk-off win of the season.

"You can shake things up, is what you can do," the Twins manager declared of his slump-busting strategy before the Twins tried to shake up their five-losses-in-six games lull. Maybe his stress simply boiled over, or maybe he genuinely felt disrespected, but Baldelli acted out that impulse in the fourth inning, when Joey Gallo was called out on a changeup that he believed missed the outside corner.

As Gallo turned to protest, Baldelli hustled out and took over the argument with home plate umpire David Rackley, who didn't listen long before ejecting him. Was the ejection deserved, or a by-the-book toss for arguing balls and strikes?

"It's probably [for] what was coming out of my mouth," Baldelli deadpanned. he argued a bit longer, then headed for the dugout.

Before he could get there, though, Rackley — apparently hearing Gallo shout something from the dugout — ejected the slump-­ridden outfielder, too, and Baldelli charged back to loudly register his objection. The manager threw his hat, shouted at crew chief Chris Guccione and finally stomped off, his arms stretched wide in disgust.

"It's great. Rocco, he put on a good show out there," credited Farmer. "That was one of the better ones I've seen."

Baldelli's ejection, the third of the season, and the second of Gallo's career, were only the tip of an odd game that included lots of adventure on the base paths. But more than anything, the Twins said, it was a heartening bounceback from a week spent floundering.

"We needed a game like that," Twins starter Sonny Gray said after allowing three runs over five innings, then declaring himself "really, really close" to returning to his dominant early-season form. "I was very proud of the guys, very happy. Everybody was emotionally invested into the whole day, into the whole game, into getting a win. You could feel it."

The victory was a remarkable one for the Twins, considering that the Red Sox, who had scored 50 runs in reeling off six consecutive victories, collected at least one hit in the first eight innings. The Twins' offense, however, was similarly amped up for a change, with four extra-base hits, including Max Kepler's second home run in two days.

Gray's uneven day began with a first-inning walk to Justin Turner that turned into a two-out run when Rafael Devers followed with a double to deep center, and Turner walloped a Gray sinker into the second deck, 447 feet away, two innings later. Gray escaped a runner-on-third jam in the fourth, but Alex Verdugo's triple into the right field corner turned into another run in the fifth, when Turner lined an RBI single.

Brock Stewart and Griffin Jax each escaped their innings without allowing a run, but Jhoan Duran did not. A one-out walk to Masataka Yoshida proved costly when pinch runner David Hamilton stole second base, then scored the game-tying run on Triston Casas' double to the bullpens in left-center.

Farmer, though, made it all moot, following Michael A. Taylor's 10th-inning sacrifice bunt — the Twins insisted afterward that he was safe — with a dramatic line-drive single, his second walk-off hit of the season.

"You never know how it's going to turn out. One hit, one win could spark the fire and start a wildfire, which is what we want to do," Farmer said. "Hopefully, today was one of them. It was a great baseball game to watch and be in the dugout and then join the game. It was just a great ballgame."