LoDo Magic seemed like a figment of someone’s wild imagination.

Then came the Rockies’ wild, 8-7 walk-off win over the Giants on Thursday afternoon at Coors Field. Orlando Arcia’s bases-loaded, two-run single to left off Giants reliever Randy Rodriguez was the abracadabra moment.

In a season full of misery and a historic number of losses, there was plenty of reason to celebrate Colorado’s first walk-off win.

“That’s big for our club,” manager Warren Schaeffer said. “It’s big for us right now, and it’s big for us moving forward. It’s something you can build on.

“Just the how — how we got there — was big. We never quit. We were down the whole game. It’s been a while since we felt like that. So, good stuff.”

Colorado entered the ninth with a 0-49 record when trailing after eight innings this season. The winning rally began with a one-out walk by Sam Hilliard. Then Thairo Estrada ripped Rodriguez for a double to left, and McMahon drew another walk, loading the bases for Brenton Doyle. Doyle smashed a grounder to third baseman Casey Schmitt for a possible game-ending double play, but Schmitt fumbled the ball for an error and Hilliard scored to make it 7-6.

Two batters later, with the Rockies down to their last out, Arcia smashed his game-winner on a 3-2 count for the seventh career walk-off of his career. Rodriguez had Arcia down 0-2.

“This feels very good,” Arcia said, using a translator. “That was a battle from the start. They were beating us the whole game. We’ve been trying to string some hits together and put the ball in play. We did that today.”

The jubilant Rockies, who mobbed Arcia and gave him a Powerade bath, snapped their five-game losing streak, avoided being swept for the 12th time this season and dodged a winless homestand. Still, with a 13-55 record, Colorado is tied with the 1932 Red Sox for the worst start in baseball’s modern era.

As thrilling as the victory was for the Rockies, it was another rough start for right-hander Antonio Senzatela. The Giants rocked him for seven runs over four-plus innings.

The Giants battered Senzatela for four runs in their five-hit second inning and three more in the third on a 438-foot, three-run homer to the second deck in right field by Dominic Smith, his first homer of the season.

“He left some stuff over the plate in the second inning, and he got hit,” Schaeffer said. “But I thought his changeup usage was better today. I thought his offspeed usage, in general, was better today. Until he went out for the fifth, it was a four-run ballgame, which gives us a chance to win.”

Senzatela is 1-11 with a 7.23 ERA and 2.03 WHIP. Opponents are hitting .373 against him. It’s as if every hitter who comes to the plate is Tony Gwynn, Todd Helton or Ichiro Suzuki in their prime. Senzatela has given up 12 home runs, tied with rookie Chase Dollander for the most on the team. At Coors, Senzatela is 1-5 with a 6.55 ERA.

After beginning the season with no earned runs allowed through his first two starts, Senzatela has posted an 8.47 ERA over his last 12 appearances (11 starts).

But the Rockies, as is their custom, rallied late.

Before the ninth-inning rally, they made the game interesting in the seventh when second baseman Estrada — the former Giant — ripped a two-run double to left off San Francisco reliever Sean Hjelle. Jordan Beck reached on an infield hit and Hilliard drew a walk to set up the rally.

The Rockies scored three runs over six innings against Giants right-hander Hayden Birdsong. Rookie shortstop Ryan Ritter’s bases-loaded, two-run single in the fourth got Colorado on the board. Mickey Moniak’s solo homer in the sixth cut San Francisco’s lead to 7-3. Moniak’s seventh homer was an opposite-field shot down the left field line.

“Day by day, I’m definitely getting more confident,” said Ritter, who extended his hitting streak to six games to begin his career, tied for the fifth-longest in franchise history. It is also the longest by a Rockies player to start their career since David Dahl’s 17 games from July 25 to Aug. 11, 2016.

Schaeffer said he “feels good” when Ritter comes to the plate in big situations. Ritter, who was on deck when Arcia hit the game-winner, liked the sound of that.

“I’m excited for big moments,” he said. “Arcia got the job done, but if he had gotten on base with a tie game, I was ready for the moment. It was cool of ‘Schaeff’ to say that.”

Colorado, 7-27 at home, opens a three-game series at Atlanta on Friday. Colorado is 6-28 on the road.