The gunman was running and shooting. Navy Capt. Christopher Mercer could hear the screaming, and the shots getting closer, outside his third-floor office. Someone had pulled the fire alarm.

Turning left, away from where Mercer was located, 34-year-old former Navy reservist Aaron Alexis paused at Michael Arnold’s office door.

Arnold was one of the Navy’s preeminent ship designers, but he was enamored with planes, finally living out his dream by building one with a kit in the basement of his Virginia home. An aviation-themed calendar was spread out on the desk in front of him when Alexis entered the office. Another staffer, who had been in the office a moment earlier, turned as he ran, and saw a silent Alexis pull the trigger, sending a shotgun blast into Arnold’s chest.

That split second gave Mercer and three colleagues time to slam the door to his office and begin pulling furniture in front of it. As soon as they backed away from the door, the gunman must have turned their way. A shot ripped through the wood, Mercer recalled, splintering it at shoulder height.

Mercer and the other three trapped employees — a young female contractor and two former Navy officers — dove under his desk.

Read eyewitness accounts from the Navy Yard shooting.

“He set up camp right in front of my office. He kept reloading and firing at cubicles. Later, when he came back, I could see his shadow through the glass pane in my door.” Mercer said Tuesday night, in his first interview since the attack. “I’ve been through my share of mishaps. But this was unreal. It was just so utterly violent.”

Huddled under his desk, Mercer became the closest thing that hundreds of police officers descending on the Navy Yard on Monday had to eyes and ears on Alexis as the guman moved through the third floor of Building 197, stalking the offices of some of the Navy’s most senior amphibious ship builders and buyers.

It was after 8:30 a.m. Mercer thought he could hear Alexis pacing through the nearly empty labyrinth of cubicles along the western side of the third floor.

Back near Arnold’s office, he would later learn, the gunman stumbled upon a young woman from Mercer’s staff who was crouching down between a filing cabinet and a metal support beam. Alexis pointed the shotgun at her face and pulled the trigger, she told others, but nothing happened. He ran.

Mercer, on the floor under his desk and armed only with his BlackBerry, began firing off e-mails to his commanders as he heard the door to the emergency staircase behind his office wall fly open.

The gunman, it seemed, was running down the stairs, toward the alleyway adjacent to the power plant where many of Mercer’s staffers had just fled. There were two shots. One of the two bullets, Mercer can only now imagine, was the shot that killed the maintenance worker standing beside Navy Cmdr. Tim Jirus in the alley.

Minutes went by, and then several more. Mercer, who leads a group designing a new $4 billion aircraft carrier to ferry the joint strike fighter, felt safe enough to climb out and sit at his desk.

He was getting bombarded with e-mails from staffers who had seen Arnold get shot. Mercer wanted to venture across the hallway to check on his friend. “I was tempted,” Mercer said. But there was no way of knowing whether it was safe. And there was no one crying for help.

Mercer was also now in communication via e-mail with his boss, one of the leaders of the Senior Executive Service, who was standing outside Building 197 beside a police commander relaying his account.

“The gunman was here,” Mercer wrote. “Is he still there?” his boss asked. “I can’t tell,” Mercer wrote. “We’re still barricaded in my office.”

Stay there, they were told. Mercer nervously passed the time clicking through Microsoft Outlook, pulling up the office numbers for Arnold and others around him. He relayed the numbers to police, to tell them where the gunman had been.

Then, there was the sound of footsteps outside again. Mercer and his terrified colleagues slid back behind the desk. The could hear Alexis reloading his weapon.

“I couldn’t believe he came back — to the same spot,” Mercer said.

In a way, it made some sense. Most offices on the second floor of Building 197 required specialized key cards to enter. The third floor was the first place where there were nooks and crannies where someone could wander.

Halfway down the west side of the building, where the looming smokestacks of the power plant next door can be seen through the windows, the gunman began to make his own last stand, sometime around 9 a.m.

“He was next door, through a little gypsum wall. He was moving furniture,” Mercer said. Mercer knew the office number. He e-mailed the coordinates: 3(W)20820.

Within minutes he could hear police. And then an eruption of gunfire.

“It was a fierce, major gun battle. Bullets were flying through my office, over our heads, and kept going for minutes,” Mercer said. “Then, I heard ‘shooter down, shooter down.’ ”

It was 9:25, Mercer remembered, when police pulled him and the three others from the office into the hall.

Mercer’s office was a wreck: Glass from frames on the wall was shattered; the floor was littered with the confetti of bullet-shredded wallboard and paper.

Outside were two officers with flak jackets and rifles. Another officer stood guard over a discarded weapon. Shell casings covered the floor.

A few steps to the south, as they walked out of a passageway into the main north-south corridor, “we literally almost had to step over Marty,” Mercer said. That was Marty Bodrog, a retired Navy officer who found a second, civilian career overseeing the design and procurement of the amphibious warships used to ferry Marines and their supplies around the world.

A day after the rampage, Mercer and the three co-workers who had huddled with him under his desk dialed into a conference call with a counselor. They practiced breathing exercises and talked about what a normal response to such a horrific event might be like.

Later, they would start retelling their stories, the counselor said. Much later they would try to make sense of it.