WASHINGTON — The Trump administration is preparing to officially ban bump stocks on guns, a move that would put an end to the sale of attachments that allow semiautomatic rifles to fire faster and that would follow through on an order President Trump made this year to the Justice Department to regulate the devices.

An administration official said on Wednesday evening that a formal ban will be rolled out in the coming days to weeks, a timeline first reported by CNN. Mr. Trump, who has in recent weeks hinted that the ban would be coming, first called for the Justice Department to re-examine the regulations after a mass shooting in February at a Florida high school left 17 dead.

The president’s declaration set into motion a chain of events that surprised officials at the Bureau of Alcohol, Tobacco, Firearms and Explosives, which had already been tasked with reviewing whether the devices could be banned, a directive given after a massacre in Las Vegas in October 2017.

In that mass shooting, the deadliest in modern history, a gunman using weapons outfitted with a bump stock device killed 58 people. The gunman fired off about 90 rounds in 10 seconds.