MESA, Ariz. (AP) -- A gunman killed one person and wounded five others Wednesday in a rampage that included a motel shooting, a carjacking and a home invasion and ended with his arrest at a nearby apartment in suburban Phoenix.

The suspect was taken into custody after officers spotted him on an apartment balcony and shocked him with a stun gun. Numerous officers led the handcuffed man to a truck parked outside an apartment complex.

Police later identified the man as Ryan Giroux, a 41-year-old ex-convict who has served three stints in state prison since 1994.

Giroux served prison terms totaling more than eight years for burglary, theft, attempted aggravated assault and a marijuana violation, the Arizona Department of Corrections said.

He was first incarcerated in 1994 and returned to prison in late 1995 before being released about a year later. He then returned to prison in mid-2007 before being released in late 2013.

Last year, a Maricopa County Superior Court judge allowed Giroux to remain on probation despite an unspecified probation violation.

Police said Wednesday's shootings started with an argument inside a motel room that spilled outside, leaving one man dead and two women wounded, Mesa police Detective Esteban Flores said.

The gunman then shot a man working at a nearby restaurant. The adult student at the nearby East Valley Institute of Technology was able to run across the street to emergency responders already at the motel, Flores said. The school said in a statement that the victim was one of seven students and an instructor working at Bistro 13 restaurant. The student was treated at a hospital and released.

The gunman got away by carjacking the instructor's car.

Police say the man then went to an apartment complex about 2 miles away, where he entered an apartment and shot a man. That victim will survive, police said.

A police officer found another man in a neighboring apartment building with multiple gunshot wounds, Flores said. He was listed in critical condition.

The shootings prompted an intense hunt for the gunman as Mesa police searched the trunks of cars, interviewed witnesses and brought in SWAT and canine units from other agencies. Flores warned people in the neighborhood to remain indoors.

Several buildings in the area were placed on lockdown amid a heavy law enforcement presence. The Arizona Department of Public Safety sent its SWAT team to Mesa to assist with the effort, DPS spokesman Bart Graves said. Scottsdale police also sent SWAT and canine units.

East Valley Institute of Technology officials said the school went into lockdown as soon as gunshots were heard. The lockdown lasted more than an hour, according to students. Afternoon classes convened but were made optional.

A nearby Mesa Community College campus issued an emergency alert, saying it was on lockdown and anyone there should proceed to the safest location. The campus remained closed Wednesday.

Vinny Carbone, who owns an auto body shop near the motel and restaurant, said he was getting ready to open when he heard a man yell "help, help" from Bistro 13 across the street. He turned and saw a woman outside the motel with what looked like a bullet hole in her side.

"She was in a chair but she was holding onto another chair, shaking, trying to keep her balance," Carbone said. "Another guy, he had blood on the back of his shirt."

Alex Martin, of Mesa, saw the chaos that ensued.

"I heard several cop cars and ambulances and fire trucks roll up past me. I get here and there's easily 20, 30 police units just swarming the roads," Martin said.

Arizona Gov. Doug Ducey promised Mesa officials any resources the state could offer.

"Right now, our hearts and prayers are with the people of Mesa, the individuals affected by this tragedy, and all law enforcement and first responders working to assist the victims," he said.

Earlier on AOL.com:

More from AOL.com:

Fallen power line leads to melted cable box, man shocked in shower

Sinead O'Connor won't be singing her hit song anymore

Real estate heir Durst is a suicide risk, sheriff says