WASHINGTON — It took just 20 seconds for police officers in Dayton, Ohio, to begin firing at a gunman one morning last month, taking him down after he killed nine people and wounded 27 others in the city’s entertainment district.

On Monday, President Trump presented six of the city’s officers with the medal of valor, the highest honor for law enforcement officers. In a ceremony at the White House, Mr. Trump said that the officers rushed toward certain danger in an effort to protect the city’s residents.

The president also awarded certificates of commendation to five people from El Paso who risked their lives to help others during a separate mass shooting at a Walmart store there a day earlier.

Together, Mr. Trump said, the recipients “responded to the worst violence and most barbaric hatred with the best of American courage, character and strength.