Having already beaten the Marlins 8-1 earlier on Wednesday, the Phillies overcame a 4-1 deficit in the second game to record their sixth consecutive victory.

Philadelphia (43-26) were down to their final out in the ninth and trailing 4-2 when Shane Victorino belted a two RBI single against reliever Leo Nunez to tie the game and send it into extra innings.

Florida's losing pitcher Mike Dunn took the ball in the 10th where he hit Phillies slugger Ryan Howard and walked Domonic Brown to set up Ruiz's walk-off hit.

"It was a long day, but at the same time, we got a big two wins, so that's very important for us," Ruiz told reporters.

In a game between two of the hottest starting pitchers in baseball, Roy Halladay allowed four runs in seven innings of the no-decision before Philadelphia reliever Ryan Madson pitched the 10th and was credited with the win.

Halladay (9-3) has won his last four decisions

Marlins starter Anibal Sanchez, who has won his last six decisions, was in line for another victory when he left having allowed two runs over seven innings but the struggling Marlins (32-36) were unable to hold on to their advantage and lost their sixth successive game.

Florida have lost 16 of their past 18 games and are now tied for last place in the National League East with the Washington Nationals.

"We were one out away from beating a team and ending a losing streak," said Marlins catcher John Buck.

"It was tough. We have to keep grinding."

Gaby Sanchez homered in the first to give Florida a 2-0 lead and Buck slugged a two-RBI single in the fourth for the visitors.

Chase Utley went 2-for-5 with two RBIs for Philadelphia.

(Writing by Jahmal Corner in Los Angeles; Editing by Greg Stutchbury)