Just after 14:00 EST (19:00 GMT) on Wednesday, two members of the National Guard, both from West Virginia, were shot at close range near Farragut Square in downtown Washington DC.
The soldiers had been on a high-visibility patrol near the corner of 17th and I streets, an area where many office workers mill around at lunchtime.
Metropolitan Police Assistant Chief Jeff Carroll said the suspect "came around the corner" and "immediately started firing", adding that the soldiers had been "ambushed".
Muriel Bowser, the mayor of Washington DC, said the incident was a targeted attack.
The location of the shooting, just blocks from the White House, meant a number of law enforcement officials were quickly on the scene to treat the two victims and apprehend the gunman.
The guard members were taken to hospital, where one later died.
Trump was at his Mar-a-Lago residence in Florida ahead of the US Thanksgiving holiday and not at the White House at the time.