Panetta said a key goal of the unannounced visit was to discuss future deployment plans with Gen. John R. Allen, the top U.S. commander, The New York Times reported.
Allen is preparing several proposals concerning U.S. force levels after the NATO mission ends Dec. 31, 2014.
Troop levels likely will be presented to President Obama "within the next few weeks" and help shape the goal for withdrawal schedules for the 66,000 U.S. troops stationed in Afghanistan, the Times said.
Panetta said Obama and his national security team would decide on the withdrawal rates only after decisions are made on what the U.S. force levels could be after 2014.
Panetta said he wanted to thank the troops, and to "consult with military commanders, to consult with leadership in Afghanistan, talk to President [Hamid] Karzai and be able to get a better sense of just exactly what's happening in Afghanistan."
The secretary said the campaign was on a better path than it was four years ago despite challenges that remain in the region, the Defense Department said in a release.
"We've got a strong campaign plan in place supported by the United States and [the International Security Assistance Force], confirmed by the NATO nations [during the NATO summit this summer in] Chicago," Panetta said, adding that a strategic partnership agreement signed June 1 by Obama and Karzai "pretty much affirms our enduring presence in Afghanistan in the long run."