WASHINGTON -- Their American flag-draped coffins behind him, a solemn President Barack Obama on Friday hailed the service of four Americans killed during the attack on the U.S. consulate in Libya, pledging to honor their memory and not "retreat from the world."At a formal ceremony in a hangar at Andrews Air Force Base, Md., Obama and Secretary of State Hillary Clinton paid respects to the four men as their remains were returned to U.S. soil.Clinton spoke first, her voice wavering as she delivered individual tributes. She described Ambassador J. Christopher Stevens' "goofy but contagious" smile, and his outsized courage."He risked his life to help protect the Libyan people from a tyrant," she said, "and gave his life helping them build a better country."Obama called all four men -- Stevens; Sean Smith, a foreign service officer; and two former Navy SEALs, Tyrone Woods and Glen Doherty -- patriots who loved their country, "chose to serve it and served it well.""Their sacrifice will never be forgotten," Obama said as four flag-draped cases rested near him. "They had a mission, and they believed in it. They knew the danger and they accepted it. They didn't simply embrace the American ideal, they lived it, they embodied it: the courage, the hope and, yes, the idealism. That fundamental American belief that we can leave this world a little better than before.""That's who they were, and that's who we are," he said. "If we want to truly honor their memory, it's who we must always be."Obama, who met with the families of the four men before the ceremony, known officially as the Transfer of Remains, repeated a vow to see that the perpetrators of the attack are brought to justice.Republicans have criticized Obama's handling of the violent unrest in the Middle East. Obama noted at the ceremony that the deaths and the continued turmoil have raised questions about U.S. involvement there. But he argued for a continued presence and recalled seeing a sign held by a man in Libya that read, "Chris Stevens was a friend to all Libyans.""That's the message these four patriots sent," Obama said. "Even as voices of suspicion and mistrust seek to divide countries and cultures from one another, the United States of America will never retreat from the world."Clinton, too, argued for continued involvement, saying, "There will be more difficult days ahead, but it is important that we don't lose sight of the fundamental fact that America must keep leading the world. We owe it to those four men to continue the long, hard work of diplomacy."And she called on leaders in those countries to do "everything they can to restore security and hold accountable those behind these violent acts.""The people of Egypt, Libya, Yemen and Tunisia did not trade the tyranny of a dictator for the tyranny of a mob," she said.After Obama's remarks, the president and Clinton clasped hands momentarily, then joined Vice President Joe Biden in a row of seats to watch as each casket was placed in a waiting hearse by military pall bearers. The remains were to be transported by air to the military mortuary at Dover Air Force Base in Delaware. Secretary of Defense Leon Panetta also attended the ceremony.The military ceremony came amid a continued spate of anti-American protests at embassies in the Middle East, Africa, London and elsewhere over an anti-Muslim video. Republican presidential nominee Mitt Romney has seized upon the unrest to accuse the administration of weakening U.S. standing in the world.The images of burning flags, breached embassies and smoldering cars have shocked the nation.The deaths on Tuesday, the anniversary of the Sept. 11, 2001 terrorist attacks, and the anti-American sentiment behind them underscored a foreign policy paradox for Obama. Many of the protests in the Arab world were in countries that underwent Obama-backed revolutions during the Arab Spring.Obama acknowledged at the ceremony that "there is no doubt these are difficult days," but he said the U.S. would not be deterred.At the White House, officials defended Obama's stewardship, saying that the administration had no "actionable intelligence" that would have prevented an attack on the U.S. consulate in Benghazi, as a British newspaper alleged.This report contains material from The Associated Press.