Iraqi police say three rockets hit the heavily fortified Green Zone. The area houses Iraqi government headquarters along with the U.S. and British embassies.
Police say the rockets were fired from a Shiite-dominated neighborhood in eastern Baghdad. No casualties were reported.
Panetta was visiting the U.S. military's Camp Victory on the capital's western outskirts at the time of the attack. He shook hands with troops and gave them a pep talk.
Panetta told the troops he is firmly focused on ensuring that al-Qaeda never again is able to attack the U.S. homeland.
"The reason you guys are here is because on 9/11 the United States got attacked," he said.
Panetta said Iraq must aggressively go after the Shiite militias that are using what he called Iranian-supplied weapons.
"We're very concerned about Iran and the weapons they're providing to extremists in Iraq," Panetta said.
"We cannot simply stand back and allow this to continue to happen" he said. "This is not something we're going to walk away from. It's something we're going to take on head-on."
Panetta pointedly pressed Iraqi leaders to appoint a defense minister, after more than a year of indecision, and to make up their minds about asking the U.S. to keep a military presence here beyond December.
"Damn it, make a decision," he told a group of soldiers. He was responding to a soldier who asked whether Iraqi leaders are ready to properly govern their country. Panetta said the Iraqi indecision was frustrating to the American government, but added that political complications are part of being a democracy.
The Associated Press contributed to this report.