The Phillies said Hamels had a "left shoulder contusion." He was hit by a Prince Fielder line drive in the top of the fourth inning. He'd thrown 45 pitches at the time and struck out six of the 13 hitters he faced.
"He didn't want to come out of the game," Phillies manager Charlie Manuel said. "At the same time I thought it was necessary that he come out. ... Once, he got hit, I figured we'd be taking a big chance to let him stay in there."
Trainers immediately tended to Hamels, who left the game with what the team called a left shoulder contusion. He was replaced by J.A. Happ.
"I'll be fine," Hamels said. "I've gotten hit in much worse spots, spots where you don't really come back as fast. I'll be able to go out there and pitch in five days."
The Brewers beat the Phillies 6-1.
Hamels said it's always scary when the ball comes back at him. He said he got hit on the back of the shoulder muscle.
"Any time you get a ball that's traveling back at you, especially from Prince Fielder, things do flash," Hamels said. "And you're just hoping it doesn't hit you in a vulnerable spot, because that can, I guess, knock you out of games for a while, or it can really mess up your head psychologically. But knowing where it hit me, I've been hit numerous times in worse areas."
Hamels was the MVP of the 2008 NL Championship Series and World Series but is off to a rough start this season. He had an 11.17 ERA through his first two starts.
He had cruised through the first three innings Thursday, striking out six of the nine batters he faced.
ESPN.com senior baseball writer Jayson Stark contributed to this report.