Brandon Nimmo never broke stride. He ran at the crack of the bat, almost oblivious to the throw that would sail wide behind him. He ran straight through home plate, stunning the delirious crowd at Citi Field. He ran to the dugout, where he was mobbed by his teammates.

Through it all, Nimmo looked like an overjoyed schoolboy, helping the Mets to a tense 4-3 victory over the Cubs Thursday night.

Yoenis Cespedes hit a tape-measure homer. Steven Matz gutted through pain to keep his team in the game. And closer Jeurys Familia concluded a stellar effort by the bullpen.

He did it with his typical drama. He loaded the bases in the ninth, thanks in part to a misplay by Nimmo. But he tore through the heart of the lineup, striking out Kris Bryant and Willson Contreras before getting Javier Baez to pop up.

But it was Nimmo, the former first rounder who was recently promoted from Triple-A, who triggered the chain of events that helped the Mets end a four-game losing streak. In his first game at Citi Field, Nimmo delivered a clutch RBI single, and propelled a comeback.

With that, the Mets went from defeated to ecstatic, scoring a victory against the juggernaut Cubs while breathing some life back into their own playoff aspirations. The victory came after a demoralizing sweep to the NL East leading Nationals.

That joy came only after plenty of pain.

Lefty Steven Matz gritted his teeth through 5 1⁄3 innings, his first start since it was revealed that he’s been pitching through the pain of a bone spur in his left elbow. He allowed a two-run homer to Kris Bryant and a solo shot to Javier Baez,

Matz departed with his team down 3-0. Before that, he stomped around the pitcher’s mound, furious with his own performance. He slumped his shoulders and muttered. After giving up his second homer, he balled his bare hand into a fist and punched the webbing of his glove.

Like the rest of his flawed team, Matz did the best he could to work around his clear limitations. Again, he avoided throwing his slider, a tell-tale sign of pain. He had briefly considered undergoing surgery before dismissing the notion, refusing to bend to the pain.

Matz’s fire emerged when came to bat in the fifth. With two runners on in the fifth, the lefty squared to bunt. But when Cubs starter John Lackey threw a fastball that sailed over his head, Matz shot a menacing glare at his counterpart.

The reaction fired up a crowd that was desperate to cheer, though only briefly. Matz flied out and the rally fizzled, though it wouldn’t be the last time a pulse of energy surged through Citi Field.

Cespedes’ solo shot in the sixth turned the tide. It rocketed off the slugger’s bat and landed in the third deck in leftfield, territory visited by only a select few.

In the dugout, Cespedes beamed after his 19th homer of the season, as if to soak in the lingering ovation. The ball was estimated to have traveled 441 feet, the longest by a member of the Mets this season.

But this isn’t the NBA. Distance counts for nothing. In the end, it was only a solo shot, cutting a deficit of three runs to two. The Mets needed more, and in the seventh, they got it.

With one out, catcher Travis d’Arnaud singled, reaching base for the third time. Alejandro De Aza and his .158 average followed with a walk.

Up stepped the fresh-faced Nimmo, who fell behind in the count to Joel Peralta 1-and-2, then battled back to make it full. It was only on the ninth pitch of a tense at-bat that Nimmo finally got one to drive, ripping a single through the center of the infield.

D’Arnaud scored from second and Nimmo advanced to second on the throw. He let loose with a wide grin and pointed to the sky after his first big-league RBI.

Moments later, he’d be smiling again. Neil Walker hit a grounder to the second baseman Baez, who fired to third base in hopes of wiping out Nimmo. But the throw sailed wide.

De Aza easily scored the game-tying run. Behind him, Nimmo motored home, putting the Mets ahead for good.