President Obama paid tribute to a shared history of sacrifice Tuesday, as he reflected on how the Philippines had surmounted the challenges of a war and a natural disaster with the aid of its American ally.

Speaking at the Fort Bonifacio gymnasium on the last day of his week-long trip to Asia, the president recalled the sacrifices that both nations made during World War II as “hundreds of thousands of Filipinos fought under the American flag.”

“Together, Filipinos and Americans put up a heroic defense, at Bataan and Corregidor. Together, they endured the agony of the death marches and the horror of the prisoner-of-war camps,” he said in the steamy gym, with Philippine and U.S. service members in full uniform standing behind him. “Sadly, the proud service of many of these Filipino veterans was never fully recognized by the United States. Many were denied the compensation they had been promised. It was an injustice.”

The United States has compensated 20,000 Filipinos and their families for their World War II service, Obama said.

In one of the most emotional points of the speech, he recognized a handful of men who fought at Bataan and Corregidor and a nurse, Carolina Garcia Delfin, who fought in the resistance — all of whom are in their 90s. “They are an inspiration to us all, and I’d ask those who can stand to stand or give a wave so that we can all salute their service,” he said as the crowd applauded.

But in a sign of how the U.S.-Philippine relationship has evolved over time, the president then shifted and recognized three men — a Philippine naval officer, a U.S. Marine colonel and a U.S. Air Force major — for being on the first aircraft that landed at Tacloban airport the morning after Typhoon Haiyan hit the city in November.

“In the days that followed, they worked together — Filipinos and Americans. Setting up a medical station. Clearing debris from the runway. Reopening that airport,” Obama recounted. “Filipino soldiers unloading aid from American cargo aircraft. American troops loading supplies onto Filipino helicopters. And when all the cargo was off those aircraft, our troops worked together to help local residents aboard so they could be evacuated to safety.”

Speaking to the three men in the audience — including Air Force Maj. George Apalisok, a Filipino American — the president told them, “You showed what friends can do when we take care of each other.” He added, “These are the kinds of missions we face today.”

Nearly six months after the devastating storm — also known locally as Typhoon Yolanda — ripped through the central Philippines, however, affected areas such as Tacloban are still working to recover.

The city’s mayor, Alfred Romualdez, said in a phone interview that of the 12,000 families still displaced by the disaster, about 2,000 remain in temporary shelters, about 6,500 are living back on the coast in makeshift shelters and about 3,000 are scattered throughout the city.

Although 95 percent of the debris has been cleared and more than two-thirds of the city’s utilities are back online, he added, water connections are down 35 percent, and only 45 percent of local businesses are operating.

“The recovery’s going to take a longer time,” Romualdez said.

The signing Monday of a new defense agreement between the United States and the Philippines has touched off protests by some Filipinos here, who consider it an effort by Americans to regain some of the control they exercised when the Philippines was a U.S. territory during the first half of the last century.

But in an e-mail Tuesday, Romualdez said the pact gives him confidence that the United States is just as committed now as it was 70 years ago to his country’s rebuilding effort. He referred to the 1944 campaign by U.S. forces under Gen. Douglas MacArthur to recapture the Philippines from Japanese occupation troops during World War II.

“Then, as now, you came full force to lift us from ground zero,” he wrote.

After Obama finished his speech in the gym and shook hands with some of the soldiers there, he visited the nearby Manila American Cemetery, the final resting place of more than 17,000 American service members as well as some Filipinos and other allied war dead.

The president walked through part of the cemetery and participated in a wreath-laying ceremony before flying back to Washington, where he arrived late Tuesday afternoon.