Trump was uninjured and was hustled away.
Guests went diving under tables as the scene unfolded and some reported hearing shots outside the vast subterranean ballroom in the Washington Hilton where the event was being held on Saturday night, local time.
One law enforcement official said a gunman had opened fire. A law enforcement officer was shot in the bullet-resistant vest but is expected to be OK, several sources told The Associated Press.
The shooting suspect - described by Trump as a "sick person" - was identified as Cole Tomas Allen, 31, of Torrance, California, two law enforcement officials told the AP.
"When you're impactful, they go after you. When you're not impactful, they leave you alone," Trump, safe and uninjured and still in his tuxedo, said at the White House two hours later. "They seem to think he was a lone wolf."
There was no immediate indication of any other involvement, and Washington Mayor Muriel Bowser said she had no reason to believe anyone else was involved.
Interviewed later, acting Attorney-General Todd Blanche said it was believed the gunmen was targeting members of the Trump administration.
Blanche said officials believe that the suspect travelled by train from California to Chicago and then on to Washington, where he checked in as a guest to the hotel where one of Washington's glitziest events was being held Saturday night.
Blanche also said he was confident King Charles would be safe during the UK monarch's visit to the US this week.
Video posted by Trump showed the suspect running past security barricades as Secret Service agents ran toward him.
"There does not appear to be any sort of danger to the public at this time," Bowser said at a separate news conference.
All officials protected by the secret service were evacuated. Those in attendance included Trump, Vice President JD Vance, Defence Secretary Pete Hegseth and Secretary of State Marco Rubio, and many other leaders of the Trump administration on a night when the nation is at war with Iran.
It was the third time since 2024 that the president had been under threat by an attacker in his immediate vicinity, including the assassination attempt in Butler, Pennsylvania, that injured him and killed a local firefighter.
"Today we need levels of security that probably nobody has ever seen before," the president said. But he also said, "We're not going to let anybody take over our society."
Acting Attorney General Todd Blanche said charges related to Saturday night's attack will be filed shortly and the investigation was ongoing.
FBI Director Kash Patel, flanking Trump, said the agency is examining a long gun and shell casings recovered from the scene, as well as interviewing witnesses from the dinner.
Guests were dining on a spring pea and burrata salad when the noise began, which Trump said he initially thought was a tray dropping but some journalists believed were five to eight gunshots.
The secret service and other authorities swarmed the room as guests ducked under tables by the hundreds.
From one corner, a "God Bless America" chant began as the president was escorted offstage.
He fell briefly - he apparently tripped - and was helped up by secret service agents. Outside the hotel, members of the National Guard and other authorities flooded the area as helicopters circled overhead.
After an initial attempt to resume, the event was scrapped for the night and will be rescheduled.
Republican Representative Mike Lawler of New York, a guest at the dinner, said he heard a pop and "we didn't know what the hell it was. And then you heard all sorts of things clatter."
In 1981, US President Ronald Reagan was shot by John Hinckley Jr outside the Hilton, an event that prompted redesigns of the property that increased security and added a special presidential suite near the entrance where chief executives could be taken.
Trump was dispatched there briefly after the incident on Saturday night.