Although the Louvre attack was swiftly contained and involved only one assailant, it was likely to add to the woes of the museum and the city, where the number of visitors declined significantly in 2016 because of successive terrorist attacks and attempted attacks. The number of visitors to the Louvre was down 15 percent from 2015, and the number of foreign visitors fell, notably from Russia, Japan, China and Brazil.

Friday’s attack also coincided with the city’s final presentation of its bid for the 2024 Olympic Games, casting something of a pall over a day that Paris officials had hoped would not be associated with terrorism.

Still, the quick response by the military was likely to ease criticism about the expense and efficacy of using soldiers alongside the police to fight terrorism.

When terrorists carried out a massacre at the Bataclan concert hall during the November 2015 attacks, soldiers were nearby but were not under orders to act and were unable to aid the police, raising questions about their usefulness. While the situation on Friday was different — the soldiers were acting in self-defense — it was described repeatedly by politicians and senior government officials as a display of preparedness and “sang-froid.”

About 10,000 soldiers are deployed throughout France, with 3,500 in the Paris region alone.

Many people were also impressed by the calm efficiency displayed by the staffs of both the museum and the Carrousel du Louvre.

The museum had several rooms designated as secure places, and guards escorted visitors to those areas.

Bastien Lopez, 21, an intern at the museum, said he was at work when “all of a sudden we saw a huge flow of people coming in the museum, and the people in charge of the security shut down the three main access doors.”