MIAMI — At its best, baseball is asked to create a sense of security, to repel the consequences of what happens outside its walls. The game is most soothing when it offers sanctuary from reality.

But last night, less than two days after the world lost Jose Fernandez, the game provided no such delineation.

Joy mingled with sorrow, cheers with silence, normalcy with grief. The thrill of a home run was greeted with tears. And, in its weakness, in its inability to block out all the pain, the game brought balance that somehow felt like perfection.

“It was really hard today to even step on the diamond,” Mets catcher Travis d’Arnaud said after the Marlins beat the Mets, 7-3, though the score barely mattered.

From the black uniforms worn by the Marlins — every player’s jersey had Fernandez and his No. 16 on the back — to the slideshow of photos that featured Fernandez’s smiling face, it was clear from the start that this was not merely a ballgame. This was first and foremost a wake, with the Mets here strictly as guests, as it should have been all along.

From the start, there was no disputing this. In the first inning, when Dee Gordon homered, he returned to the Marlins dugout unable to control his sobbing. He collapsed into the arms of his teammates, no different from any family confronted with sudden, inexplicable loss.

advertisement | advertise on newsday

“I’m pretty sure the whole world felt that emotion in that moment,” said d’Arnaud, who hid the tears beneath his mask.

To begin the game, Gordon had dug into the righthanded batters’ box, just like Fernandez, who would have pitched last night had fate not intervened. He saw one pitch — a ball — then jumped into the opposite batters’ box.

With his tribute concluded, Gordon bashed a towering homer to the upper deck in right, his first of the season. But there he stood, the joy of honoring his teammate overwhelmed by the sorrow of having to do it at all.

The crowd, so soft and silent during a moving pregame ceremony, let out a cathartic roar. In the dugout, Gordon wept.

“It was very difficult for everyone,” Bartolo Colon said through a translator.

Mets videos

So it went for nine innings, the comfort of a ballgame mixing with the emptiness death. Lines were blurred, emotions scrambled.

After Gordon’s homer, the Marlins scored six more times, chasing Colon after 2 1⁄3 innings. Afterward, Colon admitted that part of him believed the outcome was appropriate on a night of mourning for Fernandez.

“It was great for them that they were able to win,” said Colon, who had known the late pitcher. “You know what though? I would have really enjoyed it if it was him who got the win over me.”

Before the game, manager Terry Collins met with this club, emphasizing the best way to pay respect was to play the game with passion. But after the game, as if hanging on to the pretense of competition, Collins said he couldn’t be happy about Gordon’s home run.

Yet even the hardened had to admit that for this night, the game came a distant second.

advertisement | advertise on newsday

Said Collins: “The whole atmosphere was not baseball.”

Organ music replaced the blaring techno that rattles in from The Clevelander nightclub behind the leftfield fence. Between pitches, the ballpark was still, especially in the early innings.

Fans found themselves caught in between, cheering because they were at a baseball game, mourning because they were at a memorial. The unnatural quiet between the action betrayed their conflict until the very end, when they let out another roar.

“For the Mets, it’s a tough situation for them to walk into,” Marlins manager Don Mattingly said, “and they handled it with class.”

The Mets still have control of the wild card by a half game over the Giants, who were idle. The Cardinals lost Monday night and are a game behind the Giants.

advertisement | advertise on newsday

“We’ve got to get back to business now,” Collins said.

Perhaps on Tuesday, this will be the sole focus for the Mets. But on Monday, it was not. It couldn’t be, not with the hints of pain everywhere.

Before the game, a trumpeter filled the ballpark with a haunting rendition of “Take Me Out To The Ballgame”, leaving players in both uniforms to hide their tears.

Gordon thanked the Mets for being “first class,” a nod for how they ended the pregame ceremony by embracing the Marlins on the field.

“We didn’t expect that,” Gordon said after the game, when the Marlins circled the pitcher’s mound, arms slung around one another, in a silent moment for their fallen brother.

All of it was raw, the wounds still fresh. Baseball did nothing to shield the hurt, and it was just right.