"As long as there is fighting that continues in Libya, I suspect that the NATO mission will continue," Panetta said ahead of meetings later this week with other NATO defense chiefs.
Revolutionary forces supported by NATO airstrikes have seized Tripoli and much of the rest of the country, but they have been locked in a standoff over Sirte and Bani Walid for weeks.
NATO airstrikes have continued on those loyalist strongholds.
Anti-Qaddafi fighters launched their offensive against Sirte last month, but have faced fierce resistance from regime loyalists holed up inside. The battle for the city has become the focal point of efforts to rout die-hard supporters of Qaddafi, whose whereabouts remains unknown more than six weeks since Tripoli's fall.
Libyan revolutionary forces fired rockets into the western half of Sirte on Tuesday while hundreds of residents streamed out of the city to flee the fighting.
"I think the fighting has to end" before NATO can withdraw, Panetta told reporters traveling with him in the Middle East and Europe. "They can't continue to have the level of fighting that they're still having there and be able to turn to the kind of governance and issues that they're going to have to confront in order to establish stability."
Panetta said he will have better answers about the length of the NATO mission in Libya once he sits down with other NATO ministers later this week in Brussels.
The top U.S. military commander in Africa told The Associated Press last week that he believes the military mission is nearing an end.
Panetta sounded more cautious. He said NATO has made a lot of progress in the Libya mission, but while the trend is good there is still more to do.