The Mets, starting to suffocate under the burden of losing, found relief Thursday afternoon.

Whether their 5-2 win over the St. Louis Cardinals represents a building block or just a reprieve from their misery will be determined over time. Regardless, it was sorely needed, as they avoided a seventh consecutive loss and loosened the tension stemming from prolonged poor play.

It seemed ages since the Mets played this way, the components of the squad functioning in concert. It began with the starting pitcher: Jon Niese (3-4) prospered for seven and a third innings, allowing six hits and two runs. He threw 113 pitches, gave up 2 walks and notched 3 strikeouts.

It was a restorative performance for the team and the pitcher, particularly as he was coming off a pair of wayward starts. He gave up seven runs May 5 against the Atlanta Braves and eight runs May 11 against the Pittsburgh Pirates. Niese and his coaches paid close attention to his mechanics during the intervening days, as his optimal arm angle seemed to elude him.

The attention paid off, and if not for some sluggish fielding, he might have had a cleaner line. The Cardinals took a 1-0 lead in the second when Pete Kozma sliced a two-out double into the right-center-field gap, just beyond the reach of center fielder Rick Ankiel, who appeared to have a poor read on the ball. The Cardinals scored their other run in the eighth, when reliever Brandon Lyon, who inherited a pair of runners from Niese, gave up a single to Carlos Beltran.

But the Mets’ offense, comatose of late, showed a heartbeat, scoring five runs in a game for the first time since May 3. Adam Wainwright (5-3), who pitched a two-hit shutout in his last outing for the Cardinals, gave up four runs, three of them earned, over six innings. His wicked curveball still engendered limp swings as he registered eighth strikeouts, but the Mets undermined him when it mattered.