Police still were questioning the suspect, Adam Hernandez, 27, Wednesday night and authorities were determining what he would be charged with.
The marshals evidently spotted the the man later identified as Hernandez in the Chandler Fashion Center mall parking lot with a vehicle believed tied to local armed robberies, including a robbery that just had occurred at a nearby hotel, Chandler, Ariz., police Sgt. Joe Favazzo told ABCNews.com.
"It's my understanding that with very little hesitation he displayed a firearm and fired at one of the officers," Favazzo said. "Officers returned a couple of shots at him."
Nobody was hit by gunfire, which occurred around noon, police said. Hernandez then ran into the mall and eluded his pursuers, prompting the lockdown.
"They were able to quickly contain the mall," Favazzo said. "We now know that the suspect was able to get out of the mall before we got full lockdown completed."
Armed police officers wearing helmets and bulletproof vests searched the mall and a nearby strip mall for the suspect. Some of the officers used dogs in the search.
Amanda Marshall, the front desk manager of a Springhill Suites hotel near the mall, said that when the mall was evacuated, some of the shoppers came to wait in the hotel lobby for rides.
Marshall said she could see snipers on the roof of a smaller strip mall across from the Chandler Fashion Center.
"There are at least two snipers on the roof on top of the Men's Wearhouse," she said.
However, it turned out Hernandez managed to escape to the Baja Fresh restaurant north of the mall, where he evidently grew spooked by the multi-jurisdictional police response and fired his gun inside the restaurant, prompting a standoff with police, Favazzo said.
"We set up police negotiations with him," Favazzo said. "He negotiated with officers and ultimately surrendered."
About three hours after the initial gunfire, around 3 p.m. local time, a man was seen walking out of the restaurant with his shirt off and hands up. He immediately was surrounded by SWAT team members with guns at the ready, handcuffed and taken into custody.
According to a written police statement, "At least two victims/citizens were in the business while the suspect spoke to police negotiators."
Those two reportedly emerged as Hernandez surrendered.
After officers identified Hernandez as the man who shot at them, "the lockdown was lifted from Chandler Mall and the scene was determined secure," police said.
Half an hour after Hernandez surrendered, a reporter for ABC News Phoenix affiliate KNXV saw police handcuff a second person at a Sears store at the mall. That person's identity remained unknown, but KNXV reported the incident was unrelated to the shootout.
Police are trying to determine the circumstances of that incident, but Hernandez was the only person arrested for the mall shootout, Favazzo said.
During the mall lockdown, there were incorrect reports that the marshals exchanged fire with Daniel Munoz Perez, 25, a fugitive who has been on the run since last month.