For a moment, all was forgotten.

It didn’t matter that the Orioles had recently lost nine of their past 12 games as the postseason approached, or that their closer had blown a save or that their center fielder had just been shaken up after a scary collision.

No, for a moment, the Orioles were walk-off winners, and that’s what mattered to the announced crowd of 23,181 who had decided to spend their Thursday afternoon at Camden Yards, watching the faltering Orioles.

In the bottom of the ninth inning — as Orioles manager Brandon Hyde began to contemplate the 10th — Anthony Santander eliminated the need for any free baseball. He powered a two-strike, two-out home run just over the right-center field wall, giving the recently win-starved Orioles a 5-3 victory over the San Francisco Giants and sending the crowd into a long overdue frenzy.

Minutes before, Camden Yards sat deflated as the Orioles squandered a ninth-inning lead, yet another disappointment in a deluge of them. But, moments later, they had notched an elusive win, improving to 85-68 and, despite all the gloom that has surrounded their dismal performance in recent months, one game closer to the postseason. Their magic number to clinch a playoff berth is five.

“It was a breath of fresh air, for sure,” Orioles starting pitcher Zach Eflin said.

Thursday marked the Orioles’ seventh walk-off win this season, but their first in more than two months. It was their fourth walk-off home run of the year — but first since mid-May, back when the Orioles were flying high. As fans hung around Thursday, soaking in the magic, a puddle of water sat on home plate, a mark of the much-needed home plate celebration as joyous Orioles poured water on Santander.

The Orioles blew a ninth-inning lead catastrophically, as a long fly ball had dropped between diving outfielders Austin Slater and Cedric Mullins, who needed medical attention afterward but remained in the game. That allowed the Giants to tie the game at 3 and send it to the bottom of the ninth.

There, after fouling off four straight pitches, Santander lifted a slider against Giants reliever Ryan Walker. At first, though, Santander wasn’t sure it was hit well enough, worrying it would be too high.

“Keep going, please,” were his thoughts, he said.

Jackson Holliday called it, however. The rookie predicted, to Ryan O’Hearn, that Santander was going to walk it off, Holliday shared with reporters after the game.

“I thought he was going to hit a slider for a homer and, I mean, it was pretty amazing that he did,” the second baseman said.

Hyde said he was hoping for a wind gust as the ball sailed. “I was yelling, ‘blow, blow, blow.’”

The Orioles got that gust and, they hope, a boost, too. Holliday called it “unbelievable” and Hyde used perhaps an even more apt word: “needed.”

Despite a three-game losing streak and a monthslong string of injuries and poor performances, Thursday started promising enough.

On Tuesday and Wednesday, the Giants had taken early leads thanks to leadoff home runs from former Oriole farmhand Mike Yastrzemski, but on Thursday, Eflin blanked the Giants in the first inning. The right-hander finished by allowing just two runs on six hits over six innings — yet another productive outing for the trade deadline acquisition.

Even an early Giants’ lead, which came on a two-run home run from Michael Conforto, was immediately eclipsed by an Orioles rally. Santander walked to open the bottom of the fourth, Colton Cowser singled, Adley Rutschman doubled and then, with two outs, Holliday drove in two runs with a single up the middle. The second baseman punctuated his productive day by ending the Giants’ half of the following inning with a leaping catch on a line drive, stealing a hit from Yastrzemski.

“Hopefully this gives him a little bit of confidence,” Hyde said of Holliday’s strong day.

After Eflin exited, Cionel Pérez and Yennier Cano pitched scoreless seventh and eighth innings, respectively, and both were aided by their outfielders, holding up their arms in gratitude each time. First, rookie Heston Kjerstad made an excellent catch at the warning track in right field to end the seventh. Later, Mullins made a diving grab in center field in the eighth.

The Orioles entered the top of the ninth inning with a one-run lead, but closer Seranthony Domínguez, seeking his 10th save in as many chances with Baltimore this season, gave up two walks and then the doomed long fly ball to right-center field, which Mullins and Slater could not track down. It made for a scary moment for Mullins, who stayed on his knees for a while before being checked by trainer Brian Ebel.

With runners on first and second and nobody out, Donovan Walton popped out behind home plate on a failed bunt attempt. Gregory Soto then entered in relief of Domínguez and got an inning-ending double-play ball from pinch-hitter Mark Canha on his first pitch, keeping the game tied and setting the stage for Santander’s swat, his 42nd of the season.

The Orioles have lost their mojo recently, struggling for much of the summer after a blistering spring. And Thursday’s win over a sub-.500 Giants team doesn’t necessarily rectify all of their troubles, but the Orioles were able to avoid a sweep as they head into their final home series of the season against the red-hot Detroit Tigers, beginning Friday.

Thursday morning, Cowser was asked about turning the page after a loss, which the Orioles have needed to do often of late.

“It’s just kind of like, onto the next one already,” he said. “You can’t sulk for too long, especially in this game. We play so many games.”

Time is running short for the Orioles to return to their early-season form, but on Thursday, at least for a moment, none of that mattered.

Around the horn

The last three innings were played with a bat — which Giants pinch hitter Heliot Ramos accidentally let go of while following through on a swing — stuck in the netting next to the visiting dugout, hanging as a peculiar ornament.

First baseman Ryan Mountcastle is expected to begin his rehabilitation assignment this weekend, Hyde said.

Orioles left-handed reliever Danny Coulombe faced three hitters Wednesday for Triple-A Norfolk, which was planned, Hyde said, as the team decides what his next steps will be.

In Jordan Westburg’s first rehab game for Norfolk on Thursday, he batted leadoff and played all nine innings at second base, going 1-for-4 with an RBI single. Ramón Urías, playing third, went 1-for-3 with a single.

Corbin Burnes, Cade Povich and Albert Suarez will start for the Orioles this weekend against the Tigers. Burnes pitching Friday means he’ll be in line to face the Yankees for the first time this season when Baltimore visits New York next week.

Mullins eclipsed 30 steals for the third time in his career and Gunnar Henderson reached the 20-steal mark for the first time in his.