The winning run was also produced by a righthanded bat when switch-hitter Shane Victorino launched a 3-2 fastball from lefty Rex Brothers into the left-field seats to give the Phillies their first lead in the top of the 10th.
An Atlanta loss at Washington allowed the Phillies to push their lead in the National League East to a season-high seven games with the season two-thirds over.
Antonio Bastardo (5-0) pitched a scoreless ninth to earn the win and Ryan Madson pitched a perfect 10th for his 19th save.
Victorino's home run was his 10th of the season, making him the first player in baseball this season to reach double digits in doubles, triples, home runs and stolen bases. Victorino has 17 doubles, 12 triples and 15 steals.
But that at-bat would not have been possible without Mayberry's exhilarating trip to the plate with two outs in the ninth.
Trailing 3-1, the Phillies remained alive when Carlos Ruiz doubled to left field off Rockies closer Huston Street and manager Charlie Manuel sent up Mayberry to hit for the pitcher Michael Stutes.
Street, throwing all sliders, got ahead in the count 1-2 against Mayberry before throwing consecutive balls. With the count at 3-2, Mayberry fouled off a couple pitches before launching his first pinch-hit home run of the season into the left-field seats to even the score at 3-3.
The fans at Coors Field were stunned - and that included the large contingent of Phillies fans.
Pence's entertaining at-bat came the inning before.
Stutes surrendered a solo home run to Chris Iannetta in the seventh to put the Phillies in a two-run hole, but they got the tying runs into scoring position in the top of the eighth. It was an inning that once again showed how different an opposing manager must play his hand with Pence now in the lineup.
Victorino reached on a one-out single to end an impressive night by Rockies starter Jhoulys Chacin. Colorado manager Jim Tracy called upon lefthander Matt Reynolds to face Chase Utley and Ryan Howard.
Utley singled and Howard grounded out, leaving runners at second and third with two outs for Pence.
Tracy called on hard-throwing righthander Rafael Betancourt to face the hard-swinging Pence.
Coming from the lowly Houston Astros, this had to be the most important at-bat of Pence's season and even though it did not end well, it was certainly not a disgraceful effort.
Down in the count 1-2, Pence fouled off three straight 94-m.p.h. fastballs before taking a slider in the dirt. Betancourt finally won the battle, however, by throwing a 93-m.p.h. past a swinging Pence to end the inning.
The Phillies received another impressive start from Cole Hamels, who surrendered a two-run home run to Seth Smith in the second inning and nothing else. Hamels has surrendered two runs or fewer in 12 of his last 13 starts, but the Phillies are only 7-6 in those games because they are having trouble scoring for the lefty again.
Hamels allowed six hits and struck out five in six innings. He did a masterful job of escaping a bases-loaded, one-out jam in the fifth. He kept the Rockies off the board by registering consecutive strikeouts of Mark Ellis and the dangerous Troy Tulowitski.
The Phillies' only run off Chacin came in the seventh when Pence singled to open the inning and scored on a double by Raul Ibanez, who has 26 RBIs in his last 21 games.
Contact staff writer Bob Brookover at email@example.com or @brookob on Twitter.