Hamels, a 28-year-old left-hander, will collect a reported $15 million plus incentives for the 2012 season, an increase of $5.5 million from his 2011 salary. Even with the new agreement, Hamel retained the option to become a free agent after this season.
He was 14-9 with a career-best 2.79 earned run average in 2011. He finished fifth in the voting for the National League Cy Young Award. Two of the players ahead of him in that voting were teammates Roy Halladay and Cliff Lee.
Hamels is the first Philadelphia pitcher to win at least 10 games for five consecutive seasons since Steve Carlton's 13-year streak from 1972-84.
He is 74-54 in his six-year career, all of which has been with the Phillies. He was selected the NL Championship Series and World Series most valuable player in 2008.
The Phillies also said they avoided arbitration with infielder Wilson Valdez, who will collect $930,000 in 2012 after hitting .249 in 99 games last season.
Outfielder Hunter Pence is the sole Philadelphia player eligible for arbitration this year.