LOS ANGELES — The Mets’ bullpen has been a strength, its depth and quality coming through night in and night out in the season’s opening month.

But there will be nights like Tuesday, when reliever Hansel Robles came just one strike from forcing extra innings, only to watch the game-winner sail over the fence.

Pinch hitter Trayce Thompson’s two-out solo shot in the bottom of the ninth lifted the Dodgers to a 3-2 victory, ending the Mets’ three-game winning streak.

Thompson’s homer came one inning after lefty reliever Antonio Bastardo extricated the Mets out of a tight jam in the eighth inning, surviving a leadoff ground-rule double by Corey Seager.

Still, despite the loss, the Mets (20-12) remained a half-game ahead of the Nationals.

Mets righthander Jacob deGrom scattered eight hits over seven innings, his longest outing of the season. Working without his sharpest stuff or command, deGrom struck out four and walked none. But he departed with the game still tied 2-2.

The last time deGrom took the mound at Dodger Stadium, he endured the most mentally draining start of his career, walking through a six-inning minefield to rescue the Mets in a classic Game 5 of the NLDS.

With one start, on the biggest stage he had graced to that point in his career, deGrom showcased his mettle.

“Yeah,” he said with a smile, a few days before his return to Chavez Ravine. “I kinda of like it here.”

Of course, the stakes Tuesday night were nowhere close to the ones that deGrom faced on that tense October night. But the outline of his outing looked vaguely familiar, with deGrom settling down after allowing a pair of early runs.

Until Tuesday night, deGrom had handled lefties, who where just 10-for-49 (.204) against him. They had combined for just one extra-base hit. Nevertheless, Dodgers skipper Dave Roberts started six lefties against deGrom, which proved to be the right move.

Chase Utley and Seager, both lefties, opened the game with consecutive doubles to give the Dodgers a 1-0 lead. Two batters later, Adrian Gonzalez lifted a sacrifice fly. But deGrom buckled down from there, working out of a jam in the third before getting plenty of help from his defense the rest of the way.

Third baseman David Wright knocked down a scorching grounder, saving what could have been a run. Shortstop Asdrubal Cabrera made a barehanded pickup on a ball slowed down by deGrom’s deflection.

Centerfielder Yoenis Cespedes took away a Yasiel Puig hit with a leaping grab up against the wall. Later, Cespedes fired a strike from the warning track in centerfield to throw out Gonzalez at second base, just after he struck the fence with a near home run.

According to Statcast, Cespedes’ 232-foot throw was clocked at 91.1 mph.

The Mets mustered little against Alex Wood, who struck out nine in 6 1⁄3 innings. The Dodgers lefty allowed a pair of runs in the second, though the blame fell squarely on second baseman Utley.

It was Utley’s errant throw that allowed Cespedes to score from second base. One batter later, Kevin Plawecki stroked a game-tying RBI single.

The Mets’ next threat to score didn’t come until the eighth, when Dodgers reliever Pedro Baez allowed a one-out single to Juan Lagares and then plunked Cabrera on the elbow.

But Wright couldn’t catch up to a 98-mph heater and Cespedes bounced into a forceout.