The secretary-general hugged relatives of the victims of the 2011 bombing as he laid a wreath at United Nations House in the capital Abuja and praised "the extraordinary fortitude and determination" of the survivors.
"Our fallen colleagues and partners will be remembered this morning with a moment of silence in many places," he said.
"But nowhere are the memories of these colleagues more immediate, more vivid and more compelling than here in Abuja. We will remember them forever as truly the best of humanity."
Radical Islamist sect Boko Haram, blamed for the deaths of at least 15,000 people during a six-year-insurgency, mainly in Nigeria's northeast, claimed responsibility for the attack.
More From This Section
"The terrorists attacked the United Nations and destroyed the lives of many colleagues. But we have a mandate to build. To better the lives of people in need," Ban said.
The government said in a statement it had assured Ban that repairs to the building would be completed within six months.
Ban met President Muhammadu Buhari after the ceremony, congratulating Nigeria on staging free and fair elections and saying he recognised the country's "greater stability and peace" under its new leader.
"The election sent a strong global message of respect for democracy and the rule of law."
Ban said he and Buhari had discussed development, human rights and peace and security, including "the troubling levels of violence and terror perpetrated by Boko Haram in northeastern Nigeria and beyond".
"I express my strong solidarity with the Nigerian people and government and with affected families and victims," he told reporters.
"I express my solidarity again with the Nigerian people - and that the United Nations will work together in countering extremism and terrorism."