Updated

Luis Castillo hit a game-ending single with two outs in the ninth inning, lifting the New York Mets to a 6-5 victory over the Florida Marlins on Tuesday night.

Castillo, a late-inning replacement, looped a hit to the opposite field off Will Ohman (0-2) to score Ike Davis and help the Mets leap over the Marlins and into third place in the NL East.

Davis led off the ninth with an infield single that sent second baseman Dan Uggla flipping to the turf trying to make a play. After Jeff Francoeur flied out to center, Josh Thole, newly designated as the Mets' starting catcher Rod Barajas was sent to the Dodgers, hit a broken-bat single. Pinch-hitter Mike Hessman struck out before Castillo completed the Mets' rally after they blew a two-run lead in the seventh.

Hisanori Takahashi (8-6) pitched a scoreless ninth for the win.

The Mets rallied to tie it in the eighth against Clay Hensley. With two outs, Angel Pagan hustled to stretch a grounder that hit off the mound and went into center field for a double, his career high-tying fourth hit. He scored on Carlos Beltran's single, the second run-scoring hit of the night for Beltran.

Gaby Sanchez had given the Marlins a 5-4 lead in the seventh inning with a three-run homer to left field off R.A. Dickey, spoiling the knuckleballers solid outing.

The Mets took a 4-2 lead into the seventh, but Dickey gave up singles to Brett Hayes and pinch-hitter Emilio Bonafacio to start the inning. Dickey retired Hanley Ramirez on a fielder's choice and Logan Morrison on a popup to third base before Sanchez hit a line drive into the left-field seats on the first pitch he saw. His 15th home run gave Florida a 5-4 lead.

Dickey and Josh Johnson presented an enticing matchup of contrasting styles and backgrounds. A 35-year-old journeyman, Dickey was trying to match a career high with his ninth win. But in a game that felt as if it was being played on a damp, chilly September night, he gave up a season-high 10 hits and allowed five earned runs for the first time since June 28, a span of 11 starts. He struck out eight without walking a batter, using a knuckleball that dipped as slow as 53 mph in 17 mph winds.

Johnson, a 26-year-old hard-throwing All-Star, gave up six hits and four runs — three earned — in five innings. After posting a 1.35 ERA in July, he has given up three or more runs in three of his five August starts.

Errors by third baseman Wes Helms and center fielder Cameron Maybin didn't help, though.

Leading 2-1 in the third inning, David Wright hit a sharp grounder with two outs that took a late hop that Helms couldn't handle. Pagan scored to tie it. Maybin, in his first game back in the big leagues after being demoted in mid-June, had Pagan's leadoff single to center field in the fifth skip under his glove for a two-base error.

Beltran singled home Pagan and Jeff Francoeur had the second of his two sacrifice flys to make it 4-2.

The Marlins went up 2-1 in the third with sacrifice flys from Sanchez and Uggla — and a careless crowd-pleasing throw from strong-armed right fielder Francoeur.

With Hanley Ramirez on second, Logan Morrison singled to right and Francoeur threw home, holding Ramirez at third but allowing Morrison to advance to second.

Morrison advanced to third on Sanchez's fly to right field and scored on Uggla's drive to center.

New York jumped ahead in the second when Wright led off with a triple and scored on Francoeur's sacrifice fly to right field.

Notes: Marlins RHP Ricky Nolasco (torn meniscus in right knee) will have a bullpen session Wednesday that should decide whether he is capable of starting again this season. Nolasco skipped his start Sunday, and played catch Monday and Tuesday. He next scheduled start is Sunday at Atlanta. OF Chris Coghlan is out for the season with a similar injury. He was hurt July 25 during a postgame celebration. ... Mets manager Jerry Manuel said the organization has not yet decided on the innings limit for LHP Jonathon Niese. Manuel said the number will depend on the 23-year-old Niese's performance. Niese has thrown 138 innings this season. He threw 25 2-3 innings last year and 14 in 2008. ... Mets minor league pitcher Lachlan Hodge was given a 50-game suspension after testing positive for an amphetamine. He plays for rookie-level Kingsport of the Appalachian League.