The ugliest game in which the Mets have participated this year — or at least a strong contender — had a sexy starting pitching performance Wednesday.

Bartolo Colon took the pressure off his struggling lineup and overworked bullpen with his best outing in a Mets uniform. With the 41-year-old righty throwing 7 ¹/₃ scoreless innings, the Mets won their second straight, 5-0 over the Pirates at Citi Field.

Colon (4-5) allowed five hits, struck out nine and walked one over 121 pitches. The pitch total was Colon’s highest since throwing 128 for the Angels on Aug. 18, 2004, against the Rays.

“I feel really good, thank God, and when you have a game like that you feel even better afterward,” Colon said.

The Mets (24-28) finished with two victories in three games against the Pirates for their second series win in May.

Colon had made four straight starts on the road, and struggled in three of them. But at home he has posted a 2.30 ERA over four starts.

“Bartolo is a perfect guy for here,” manager Terry Collins said. “This could be a place as we get into the summer we’ll try to make sure we schedule games for him in this park.”

The victory helped the Mets forget a turbulent 4-5 homestand in which general manager Sandy Alderson dumped hitting coach Dave Hudgens on Monday and replaced him with minor-league hitting coordinator Lamar Johnson.

“I didn’t expect anybody to hang their heads about it,” David Wright said. “You say your goodbyes and when that next day comes, you’re back to work.”

Lucas Duda hit a two-run homer in the eighth inning, giving the Mets the insurance they needed on a day neither team was crisp: Four errors were committed and the Mets had two base-running blunders. Pirates pitcher Charlie Morton also threw two wild pitches.

Ike Davis came to the plate as the tying run in the eighth, but hit into an inning-ending double play against Jeurys Familia to keep the Mets’ lead at 3-0.

Those two base-running miscues hurt the Mets. In the fifth, Juan Lagares was caught attempting to steal third with two outs, leaving Wright at the plate. In the sixth, Chris Young attempted to advance from second to third on a pitch in the dirt and was nailed.

Wright’s solo homer in the sixth extended the Mets’ lead to 3-0. The homer was Wright’s fourth of the season — all of which have come at Citi Field.

“I’ve said all along the home runs don’t concern me,” Wright said. “I judge my at-bats and my production by other things than just home runs.”

Wright’s RBI single in the third gave the Mets a 2-0 lead. Daniel Murphy started the rally by reaching on Pedro Alvarez’s throwing error. Murphy raced to second on the play and took third after Jordy Mercer mishandled the throw from Neil Walker.

The Mets got a run in the second without the benefit of a hit. Duda walked leading off the inning and reached second on a wild pitch before advancing on a groundout. Morton’s second wild pitch of the inning scored Duda.

Wright had a throwing error in the fourth and another in the sixth, but neither ended up hurting the Mets.

Over the final eight games of the homestand, the Mets held opponents to 8-for-58 (.137) with runners in scoring position. Colon and Familia combined to hold the Pirates hitless in seven such at-bats Wednesday.

“I just feel good when I’m at home,” Colon said. “Now I’ve got to get ready to pitch on the road as well.”

In their upcoming 11-game road trip that begins Thursday, the Mets will face the Phillies, Cubs and Giants.

“It’s going to be a lot of miles traveled against good teams,” Wright said. “Hopefully this can keep us going and jump-start the offense.”