PITTSBURGH — A three-run homer by Starling Marte in the seventh inning broke open a tight game and the Pittsburgh Pirates ended the Mets’ seven-game winning streak with an 8-4 victory on Friday night.

The Pirates led by 5-4 when Marte turned on a pitch from Tyler Bashlor and sent it into the seats in left field for his 19th home run of season.

Melky Cabrera hit a two-run double during Pittsburgh’s five-run fourth inning against Steven Matz (6-7). Jose Osuna, starting at third base after the Pirates designated Jung Ho Kang for assignment, had two hits and drove in a run for the Pirates.

Trevor Williams (4-4) overcame a shaky start to pick up his first victory since May 10.

Pete Alonzo, Robinson Cano and Amed Rosario each had two hits for the Mets, who lost for just the sixth time since the All-Star break when Matz couldn’t protect an early three-run lead.