Nato chief Anders Fogh Rasmussen has said the organisation is proud to have helped Libya during the uprising against the late Col Muammar Gaddafi.
Mr Rasmussen is in Tripoli to mark the official end of Nato's Libya mission.
He said Nato could help Libya's new rulers with security and the transition to democracy if requested.
Nato forces, acting under a UN Security Council mandate to protect civilians, began operations in March as Gaddafi forces moved to crush the uprising.
The Nato mission formally comes to an end at one minute to midnight Libyan time (21:59 GMT) on Monday.
Mr Rasmussen said he had held talks with National Transitional Council (NTC) leaders, including its chairman Mustafa Abdul Jalil, about Libya's future and the roadmap for transition to democracy.
"You've acted to change your history and your destiny; we acted to protect you. Together we succeeded; Libya is finally free, from Benghazi to Brega, from Misrata to the Nafusa mountains, and Tripoli," he said at a news conference.
"Many countries in the Arab world know us and trust us; many acted with us to protect you. I hope that the free, democratic Libya will join us as a partner one day soon; but this is up to you. The future of free Libya is finally firmly in your hands."
Mr Jalil expressed Libya's gratitude for the help received from Nato forces and other foreign forces, as well as the Libyan rebel forces.
Earlier, Mr Rasmussen said Nato could help with "defence and security reform", but that it was time for the United Nations to take the lead in international assistance for Libya.
He also said Nato's Operation Unified Protector in Libya was "one of the most successful in Nato history''.
The first missions were flown on the evening of 19 March, as Col Gaddafi's forces approached the rebel-held city of Benghazi.
With the help of America's massive military machine, Nato managed to sustain the Libya operation.
Overall, its warplanes flew more than 26,000 sorties, including nearly 10,000 strike missions. More than 1,000 tanks, vehicles and guns were destroyed, along with Col Gaddafi's command and control network.
Mr Rasmussen said Nato's military forces had prevented a massacre and saved countless lives.
"We created the conditions for the people of Libya to determine their own future," he said.
Despite the expected formal announcement that Nato's mission is over, Western powers are likely to be involved in Libya for some considerable time, says the BBC's Jonathan Beale.
The Security Council decided to end its role, despite a call by the NTC for Nato to continue its military action.
The Libyan envoy to the UN had said the NTC needed more time to assess its security needs. But diplomats said that the mandate to protect civilians had been accomplished, and any further security assistance would have to be negotiated separately.
A small team of military advisers remains on the ground to aid the NTC. US and British experts are also trying to ensure that the surfeit of weapons in the country does not end up in the wrong hands.