BALTIMORE — The horses, a rumor of thundering hoofs and distant roars disappearing into the fog at the first turn, made an invisible loop around Pimlico Race Course’s liquid track, then suddenly reappeared out of the gauzy mist and came heaving and splashing down the homestretch. Out in front was the strapping chestnut colt named Justify, his white blaze the first thing to come into view. But behind him — and keeping pace, if not gaining — was a pack of rivals.

As he has across the entirety of his brief and meteoric career, Justify answered the challenge and prevailed Saturday, winning the 143rd Preakness Stakes and keeping alive his Triple Crown hopes.

Tested like never before, Justify, an overwhelming 2-5 favorite, ran neck-and-neck with rival Good Magic for much of the race, seized the lead coming out of the last turn and held off late-charging Bravazo down the stretch for a half-length victory, the smallest by far of his five career wins. Tenfold also closed hard and finished third by a neck. Good Magic faded to fourth.

“It was by far his hardest race,” said Justify’s jockey, 52-year-old Mike Smith. “A bit of the greenness came out today, but he was also pushed today early on.”

In three weeks, assuming he emerges in fine health from Saturday’s grueling slog through the mud and fog, Justify, with the Kentucky Derby and Preakness already secured, will race at Belmont Park on Long Island with a chance to become just the sport’s 13th Triple Crown winner.

Saturday’s race somehow brought out a new, previously unseen attribute in Justify — a bit of grit and heart, which he had never before required — while also making him appear more beatable than he has at any other time. His previous four victories had come by a combined 21½ lengths, with his 2½ -length win over Good Magic at the Derby the smallest.

“Good Magic, he put it to us,” said Bob Baffert, Justify’s trainer, who won his seventh Preakness and 14th Triple Crown race. “They didn’t give it away. He was going to make us earn it. I wasn’t liking it. . . . But this is what makes horse racing so great. They find themselves when they get in this position. He’s not just this big, beautiful horse — he is all racehorse. He was in a fight the whole way.”

By late afternoon, the rain and drizzle that soaked the grounds all week — and a crowd of 134,487 all day — had largely abated, replaced by a thick blanket of fog that gave the proceedings a spooky, mystical vibe. On a clear day, you can look out from Pimlico’s upper levels and see the Francis Scott Key Bridge on the city’s south side, some 15 miles away.

On Saturday, you could barely see the infield.

Some two-thirds of the race was all but invisible from the grandstand, the giant video screen with NBC’s multicamera feed the only way to see what was happening. Even Justify’s connections could only watch the screen and wait for the horses to make the final turn.

“When they turned for home and I couldn’t see them, that scared me to death,” said Kenny Troutt of WinStar Farm, Justify’s owner. “And finally they showed up right there, and boom.”

Jose Ortiz, atop Good Magic, went to the lead out of the gate and remained within a half-length of Justify, on the inside, for almost the entire race.

“I looked over and saw Good Magic,” said Smith, Justify’s jockey. “I said, ‘Oh, man. It’s going to be a match race from this point on.’ ”

Only on the homestretch did Good Magic begin to fade, by which point Bravazo, trained by Hall of Famer D. Wayne Lukas and ridden by Luis Saez, made a late charge. Smith, aboard Justify, felt the late challenge but knew he was nearly to the wire and said he didn’t ride Justify as hard as he could have.

“A very good horse won the race,” Lukas said. “We ran at him. We kept him honest, just like we said we would.”

Three years ago, Baffert brought another precocious Kentucky Derby champion to Pimlico and dashed through a sudden and violent thunderstorm to win by seven lengths. Three weeks later, that colt, American Pharoah, became the sport’s first Triple Crown winner since Affirmed in 1978, ensuring his place in its history. Between those two wins, 13 other horses, including three of Baffert’s, had secured the first two jewels only to fail to complete the crown.

Baffert has not been shy about evoking Pharoah’s name in speaking of Justify, gushing about how both horses “just glide over the ground.” Because Justify, a strapping 1,280 pounds, has about 100 pounds on Pharoah, Baffert has taken to describing them, respectively, as LeBron James and Michael Jordan.

In just 90 days, Justify has gone from an untested and mostly unknown colt who had never been saddled in a race to the sport’s biggest superstar since American Pharoah himself.

Baffert himself didn’t lay eyes on Justify until just four months ago. The first time he worked him out at Santa Anita, Baffert came away thinking, “We have a shot.” He meant: a potential Derby champion. But the road from there to here was a steep one, given Justify’s lack of experience at that point — and the fact that no horse since Apollo in 1882 had won the Derby without having raced as a 2-year-old.

Justify raced for the first time Feb. 18, winning a maiden race at Santa Anita by 9½ lengths and immediately establishing himself as a Derby contender. By early April, he was winning the Santa Anita Derby by three lengths, announcing himself as the Derby favorite.

In the month of May alone, Justify has ended the so-called Curse of Apollo, won once in the rain and once in the fog, overcome a bruised heel suffered in the Derby and survived the toughest race of his career.

“He has to show us,” Baffert said when asked if Justify would go to Belmont. “He has to come out of the race well, and he has to be training really well. He’ll dictate it. We’ll get him back to Kentucky and see how he trains. But right now, I don’t see why not.”

With a Triple Crown within reach, how could Baffert not take his horse — barring injury — to Belmont? History will expect it. The industry will demand it. And Justify, having done everything asked of him to this point, will have earned it.

Read more from The Post: