The visit comes after rebel forces ousted and killed Muammar Qaddafi, who ruled Libya for more than four decades and whose short-lived détente with the U.S. ended when the Obama administration joined with NATO allies in aiding what amounted to a revolution.
Panetta, arriving in Tripoli for meetings with Libya's new leaders, said the United States stands "ready to offer assistance in the spirit of friendship and mutual respect."
"There is no doubt that you will confront some difficult challenges -- bringing together all of the revolutionary forces that fought from west to east, securing weapons stockpiles, professionalizing the army and police, and developing the institutions of a free and representative government," he said at a press conference with the Libyan Prime Minister Abd al-Raheem Al-Keeb.
Panetta's lumbering C-17 military transport plane landed in the capital just days after a militia that controls the airport tried to assassinate the current Libyan army chief. General Khalifa Hiftar was nearly killed as his convoy tried to skirt through an armed checkpoint. This was followed by a rocket attack on the airport. One of Hiftar's sons reportedly was injured at a separate exchange at a Tripoli bank.
There was no sign of the fighting, though, as Panetta touched down on the tarmac and was greeted by the U.S. ambassador. He was swiftly escorted in a motorcade to the prime minister's office, past the graffiti-splashed walls of the destroyed Qaddafi compound. Few signs of war except the rubble at Bab Al Azia, Qaddafi's home and headquarters, were evident -- but tension and concern that the fledgling Libyan government is struggling to gain control and consolidate the armed militias and tribes in the wake of Qaddafi's fall served as a backdrop.
While no U.S. defense secretary had ever touched down on Libyan soil, the country's history repeatedly has crossed paths with America's.
The Marines sing about the "shores of Tripoli" and 13 U.S. sailors remain buried at a Protestant cemetery there, casualties of the Barbary pirate wars. Their ship, the Intrepid, was sent by President Thomas Jefferson as part of an effort to halt the pirates threatening U.S. merchant marine ships in 1804.
The Libyan war, which cost nearly $1 billion and no U.S. lives, could be a new model for how the U.S. military, facing severe budget cuts, fights in the future -- relying on the NATO alliance and technology rather than boots on the ground. But as with Iraq and countries gripped by the Arab Spring, the last chapter may not have been written.
Following the cool reception that the American delegation received in Baghdad in a small and sparsely attended ceremony to mark the end of that war, the U.S. delegation in Libya was received with great warmth.
After meeting the Libyan prime minister and defense minister, Panetta made his way to the Protestant cemetery on the edge of Tripoli where historians believe the remains of the 13 U.S. sailors killed in 1804 are buried.
The walled cemetery sits on a hill overlooking the corniche and the Mediterranean Sea. It is immaculately kept with a marble slab paying tribute to the 13 U.S. sailors. A few years ago Qaddafi, at the request of the United States, renovated the cemetery, which is the final resting place of about a dozen or so other American and European expatriates who died in Tripoli. Some were doctors. Some were children.
Panetta, U.S. Ambassador Gene Kretz and U.S. AFRICOM Commander Gen. Carter Ham stood solemnly before the American grave marker and said a prayer. After a moment of silence, Panetta left one of his secretary of defense coins as a sign of respect.
The Libyan drivers kept thanking the United States. The atmosphere of appreciation for the U.S. and NATO efforts stood in marked contrast to the cool, if not hostile, reception that Americans feel in Baghdad and Afghanistan these days.
The story of how the 13 sailors died, their mission and the challenge that Jefferson, a reluctant wartime president, faced 200 years ago echo recent challenges faced by President Obama in the aftermath of the downing of a valuable U.S. drone over Iranian territory.
The president faced a decision to send in forces or call in an airstrike to destroy the valuable U.S. military asset captured by the Iranians. In the end he decided against such a measure.
In 1803, Jefferson sent the Philadelphia, a naval frigate, on a secret mission to confront the pirates, but the Philadelphia ran aground, was captured and the sailors onboard were taken captive. Jefferson then ordered the Intrepid along with 70 volunteer sailors under the cover of darkness to retrieve or burn the Philadelphia. They burned it and killed 25 pirates in the process. The American sailors returned to the Intrepid.
A few months later, Jefferson ordered the men of the Intrepid back into the Tripoli harbor to destroy more pirate vessels. This time they rigged the Intrepid, a dual mast ketch, with explosives. The plan was for it to be used to blow up the harbor. The sailors would attempt to row quickly away from the harbor. Instead the ship blew up prematurely and all 13 U.S. sailors were killed.
Their bodies washed up on shore and legend has it were dragged through the capital and fed to dogs until American POWs from the Philadelphia were ordered to dig a mass grave for the remains. In 1949, those remains were reburied in the Protestant cemetery outside the capital. The graves have been maintained ever since. Qaddafi, at the U.S. request, even had high walls built around the cemetery to protect it.
Relatives of those who died, including a Republican state legislator who is the descendent of Lt. Henry Wadsworth, are demanding the sailors' remains be repatriated. The current defense authorization bill requires the defense secretary to study whether it is feasible to do so.
The Navy's position is that the sailors were given a proper burial, and successive Navy secretaries have said they would like for the graves to remain where they are, as long as they are cared for with respect.
During Panetta's visit, he said, "Even in the most difficult of times, the Department of Archaeology and Antiquities worked hard to protect and preserve this special site, spending significant resources to restore the cemetery to its original state and taking painstaking measures to protect the remains of our fallen sailors."
Jennifer Griffin currently serves as a national security correspondent for FOX News Channel . She joined FNC in October 1999 as a Jerusalem-based correspondent. You can follow her on Twitter at @JenGriffinFNC.