The number of homicides in Washington, D.C., soared 38% last year, a setback in the capital’s safety record that defies the national trend of fewer murders.

The district recorded 160 homicides in 2018, up from 116 a year earlier, police said. While violent crime overall fell 7%, authorities said an increase in the use of guns in crimes such as robbery and the growing lethality of shootings led to more homicides.

The...