For hours on Monday morning, scores of law enforcement officials, police commanders and representatives from at least 48 agencies sat in a room on the second floor of Police Headquarters in Lower Manhattan and imagined the worst.

Two active gunmen, one at a hospital, another at a train station.

A power failure.

A building collapse on Cliff Street, a few blocks west of South Street Seaport.

The unlikely series of hypothetical events were part of a large-scale tabletop exercise in preparation for the visit of Pope Francis to New York, which begins on Sept. 24.

The visit, which is the pope’s first to the city, coincides with the United Nations General Assembly, where heads of state from about 170 countries are expected to attend. Francis will address that gathering, but from a security standpoint, his other activities provide greater challenges, given his desire to connect directly with people on the streets: a visit to an East Harlem school; a procession through Central Park.