A ninth-inning meltdown was only inches away Tuesday night for the Texas Rangers, and the only thing that could prevent it would be a spectacular diving catch or a spectacular base-running blunder.

Craig Gentry knew the stakes as he raced in from center field on a sinking liner. If he were to dive and miss the ball, his team would blow a four-run lead and fall to an improbable loss at Wrigley Field.

Even if he were to play it safe, the best-case scenario would have been a tie game.

But the ball wouldn’t drop, and Gentry thought he could catch it. He dived, and the resulting catch pulled the Rangers’ bullpen out of a nosedive and into a smooth landing with a 4-2 victory over the Chicago Cubs.

“In that situation, it’s definitely a big catch,” said Gentry, who humbly placed the catch in his career “top five or six.”

“That’s the game right there. If that ball drops, we’re probably still playing. The closer I got to it, it kept hanging up. I knew I had a play on it. I took a small gamble there, but it ended up paying off.”

Derek Holland should have been the story of the game after allowing only two hits in seven scoreless innings. Adrian Beltre had a big night, too, with a two-run homer as the Rangers jumped to what appeared to be a cozy 4-0 lead on a chilly night.

But Michael Kirkman and Joe Nathan nearly let the cushion slip away.

Nathan was summoned with two outs after Kirkman retired the first two hitters but allowed a single to Starlin Castro and a walk to Anthony Rizzo.

Nathan got Alfonso Soriano to hit a weak grounder, but Elvis Andrus had no play, and the bases were loaded. Pinch hitter Nate Schierholtz followed with a looping fly ball that hit off the glove of left fielder Jeff Baker for a two-run single that left runners at second and third.

Welington Castillo was next, and Nathan hit him on a two-strike pitch to load the bases.

Up came Darwin Barney, who has been activated from the disabled list before the game, and he flipped a liner to center field on the eighth pitch of his at-bat. Gentry charged in, dived head-first, and stunned the announced crowd of 29,344.

“The best-hit ball of the inning ends the game,” Nathan said. “Fortunately for us, Craig makes a great play on it.”