WASHINGTON — After more than five hours of baseball between his Pirates and the Nationals, Starling Marte had all he could take.

“Too many innings,” Marte said. “We were tired. It was time for a home run.”

Marte's solo shot off Oliver Perez in the 18th inning Sunday gave the Pirates a 2-1 victory. The only longer game in the majors came July 1 when the Indians beat the Blue Jays in 19 innings.

“I just love the grit of our club,” said manager Clint Hurdle, whose Pirates snapped a three-game losing streak. “I don't know if it builds character. It definitely reveals character.”

It took 17 pitchers combining for 540 pitches in a game that lasted 5 hours, 48 minutes. It was close to ending a lot earlier. The Nationals were down to their last strike in the ninth inning when pinch hitter Daniel Murphy hit a tying home run.

Murphy, who was out of the lineup for the third consecutive day with a sore left hamstring, took All-Star closer Mark Melancon deep on a 2-2 cutter.

In extra innings, it turned into a battle of attrition.

The Pirates could have taken the lead in the 16th on a double by Josh Harrison, but a perfect relay from Nats center fielder Michael A. Taylor to shortstop Danny Espinosa to catcher Wilson Ramos nailed Eric Fryer at the plate.

“It's the best relay in the history of the game in the 16th inning,” Hurdle said. “Ever.”

Marte's home run came on a swing the Nationals didn't even want him to get. Manager Dusty Baker wanted to intentionally walk Marte but couldn't get the signal to Ramos in time.

“I didn't put the (four) fingers up soon enough to walk him,” Baker said. “Before I could, he hit the first pitch out of the ballpark.”