What a waste.

Inexplicably, the Mets did everything they could to undo all the good R.A. Dickey had done on the mound. Closer Francisco Rodriguez blew his second consecutive save and Jason Bay, who was inserted into the cleanup spot for the first time since June 3, went 0-for-5 with three strikeouts.

That is, until Justin Turner saved the day with, of all things, a bases-loaded hit-by-pitch.

Oakland reliever Brad Ziegler hit Turner on the leg with a low sinker to force in the go-ahead run, resulting in a 3-2, 13-inning victory for the Mets early Thursday morning at Citi Field.

Those who endured the 63-minute rain delay had to wait another four hours to witness the Mets’ first walk-off win since October 1, 2010.

Bobby Parnell (2-1) earned the victory for the Mets (36-38), who are 3-4 in extra-inning games.

advertisement | advertise on newsday

“I’m staying there and holding my ground unless it’s at my face or around my ankle,” Turner said of the game-changing at-bat. “I’ll stay in there and take the bruise to get that game over with.”

After the game, a visibly miffed Ziegler said he thought Turner leaned into the pitch. “I haven’t seen the replay, but if he did, it’s kind of a cheap way to win,” said the righthander, who hit Turner on the first pitch of the at-bat.

Lucas Duda, whose single gave the Mets a 1-0 in the second, singled with one in the bottom of the 13th. Then Daniel Murphy, who was benched in favor of Duda because of his struggles at the plate, lined a single into leftfield. After Angel Pagan flied out, Ziegler intentionally walked Jose Reyes to load the bases for Turner.

“One of the coaches just said, ‘If we’re going to win this game, somebody’s going to get hit with a pitch here,’” manager Terry Collins said. “I said, ‘Why didn’t you call that in the ninth for heaven’s sakes, if that was the case.’”

Though the result was a positive one for the Mets, a masterful performance by Dickey — one run and three hits and nine strikeouts in eight innings — was not rewarded. His effort was a marked improvement from his previous start, in which he tied a season high by allowing six runs and six hits in four innings.

There were 17 strikeouts between he and Oakland starter Gio Gonzalez (6-5), who struck out eight and allowed one run and four hits in seven innings. But the lefthander was outdone by Dickey.

“I had fun tonight,” Dickey said. “I had a good fastball tonight. I had a good low sinker and I was able to change speeds with my knuckleball.”

Dickey had been masterful for four-plus innings, striking out six batters before Kurt Suzuki ripped his fourth homer over the leftfield wall to tie the score at 1.

The Mets, who had ample opportunities to score, stranded 15 runners — including three in the 12th. Reyes singled with one out and moved to second on Turner’s groundout. After Ziegler intentionally walked Carlos Beltran, pinch hitter Josh Thole walked to load the bases. But Jason Pridie grounded out to end the inning.

Reyes (2-for-6) put the Mets up 2-1 in the eighth when he tripled (his 13th) and scored on Turner’s single.

advertisement | advertise on newsday

Rodriguez gave the lead away in the ninth. Coco Crisp doubled with one out, stole second and scored on Conor Jackson’s single. The last time Rodriguez blew back-to-back saves was in August, 2009.

“You know what, I’m going to speak as a fan. I’m not going to speak as a player,” Rodriguez said. “Definitely I have to get my head out of my butt, pretty much. Simple as that. Those pathetic outings, they’re really pathetic. I’ve just got to get it done. I have to find a way to go out there, start making quality pitches and start getting people out. Because it’s been really embarrassing this month, pretty much.”

Despite the missed opportunities, Dickey said he had fun watching from the dugout.

“Anytime you get a walk-off win, I think it energizes your club a little bit,” he said. “We haven’t had one here at home and we needed one badly.”