A bespectacled 22-year-old man clad in tactical gear opened fire with an assault rifle outside a federal courthouse in downtown Dallas on Monday before being shot dead in an exchange of gunfire with officers, officials said.

The masked gunman — identified as Brian Isaack Clyde — died at the scene and was taken to Baylor University Medical Center after he shot the rifle at the Earle Cabell Federal Building, FBI Special Agent in Charge Matthew DeSarno said.

No civilians or law enforcement officers were injured in the incident, which occurred a block from the site of a July 7, 2016, ambush in which a gunman killed five cops and wounded nine others.

“At this time we have no information indicating that there are other shooters or other threats to the community,” said DeSarno, who added that Federal Protective Services officers shot the gunman.

Federal agents said they do not believe Clyde was working with anyone, DeSarno said.

Neither he nor US Attorney Erin Nealy Cox provided any indication why Clyde would target the building, which houses federal courts, the US Attorney’s office for the Northern District of Texas, a passport office and US Marshals Services.

A bomb squad examined a vehicle associated with Clyde as a precaution and performed controlled explosions that rocked downtown and sent chills through already unnerved residents.

Police canvassed the area for other possible devices as many buildings were placed on lockdown or evacuated.

The Dallas Morning News reported that one of its photographers, Tom Fox, was at the courthouse to cover a trial when the man parked nearby and opened fire in his and a security guard’s direction, hitting and cracking the glass front door.

Inside the building, other guards pushed everyone down to the floor.

“It was pretty close range, I was crouched behind a wall next to the back door on Jackson Street and shots were fired down at Jackson and the gunman came up the street alongside the federal building,” Fox told NBC 5.

“He stopped to pick something up and I shot a few frames of him and then crouched back behind the wall. Then he came up to the door and shot out the door on Jackson Street and he never passed me, fortunately,” he added.

One of Fox’s images, which he said he shot with an iPhone, showed officers standing around a shirtless Clyde lying on the ground. He had a red heart tattoo with a black drawing inside — possibly of an animal — on his left arm.

“I’m just thankful to be alive,” he told NBC 5. “Literally I was just around the marble podium, or marble wall, from where he shot out the windows and I was just praying that he wasn’t going to pass me, pass that wall because if he saw me crouch there he probably would have shot me.”

Ed Modla was working from home when he heard a volley of about 10 loud shots. When he looked outside, he saw the gunman running across Griffin Street.

“As soon as I saw the shooter, I got the hell away from the window,” he told the Dallas Morning News.

Another witness, Don Miles, said he heard up 10 to 15 shots as he walked up to the Commerce Street entrance for a 9 a.m. appointment.

“I just ran,” Miles told the paper.

Kelly Carter, who lives near the federal building, said he heard the gunfire and saw part of the chase from his apartment.

“I saw the guards return fire and chase somebody into the parking lot in front of our building,” Carter told NBC 5. “I knew it was gunfire immediately. So, I just figured it was an active shooter or something like that.”

Carter said he was evacuated out of an abundance of caution.

“I knew immediately that this was right outside of my window. I could smell the gunpowder at my place, yeah it was that close,” he told the station. “I could hear ricochets going down Jackson Street.”