For about two and a half minutes, at least five Pennsylvania law enforcement officers converged around the warehouse where a gunman had clambered onto a roof near a rally held by former President Donald J. Trump, struggling to reach the attacker before he shot at Mr. Trump, newly released police videos and a social media video show.

The body-cam and dashcam footage, paired with an eyewitness video posted on YouTube, provide new insight into the presence of and the response by Pennsylvania law enforcement at the building where the gunman, Thomas Crooks, was positioned. They reveal for the first time the critical moments — starting around 6:08 p.m. — when officers establish Mr. Crooks’s location, frantically try to find a way to get onto the roof and determine that he is armed. By around 6:11, Mr. Crooks opens fire.

Before the release of the videos, the exact movements of nearby law enforcement officers — and the actions they took to address a newly identified threat — were unclear. Testimony from state police and Secret Service officials provided some details, but the footage obtained by The New York Times through a public records request gives the first second-by-second retelling from the perspectives of two of the officers near the gunman at the time of the shooting.

The footage also raises more questions as to why the Secret Service failed to remove Mr. Trump from the stage in Butler, Pa., on July 13, while local law enforcement officers were scrambling to get to Mr. Crooks, even if they weren’t yet aware that he had a firearm.

The footage analyzed by The Times includes 12 videos released on Thursday by the Butler Township Police Department, showing at least three Butler officers and one Pennsylvania state trooper focused on the roof from where Mr. Crooks fired. Eyewitness footage previously published on YouTube shows that a fifth law enforcement officer was also responding in the same area.