WASHINGTON — President Trump paid tribute on Tuesday to the airline passengers and crew members who stormed the cockpit of a hijacked plane and thwarted terrorists in the skies over Pennsylvania on Sept. 11, 2001, vowing to follow their example by standing up to evil in the world.

In his first trip to Shanksville, Pa., as president, Mr. Trump led a ceremony marking the 17th anniversary of the terrorist attacks by honoring the heroes who brought down United Airlines Flight 93 into an unpopulated field rather than allow it to be used as a weapon against the nation’s capital.

“We remember the moment when America fought back,” Mr. Trump said in a televised address at the Flight 93 National Memorial at the site of the crash, which killed 40 passengers and crew members. Referring to those on board who rose up that day in an effort to take back the plane, he said, “They boarded the planes as strangers and they entered eternity linked together as true heroes.”

Ceremonies were also held Tuesday in New York, where two hijacked planes slammed into the twin towers of the World Trade Center, and at the Pentagon, where another plane was used to attack the headquarters of the American military. Vice President Mike Pence and Defense Secretary Jim Mattis led the commemoration at the Pentagon. “The evil that descended on America 17 years ago still lingers in our world,” Mr. Pence warned.