Law-enforcement officials said a false alarm of a gunshot at the Washington Navy Yard prompted a huge response from security officials concerned about possible violence ahead of the July 4 holiday weekend.

The facility was in lockdown for several hours Thursday morning as multiple law-enforcement agencies responded in tactical gear.

The episode...