Updated

An hourslong standoff with an armed man who barricaded himself aboard an Amtrak train ended early Saturday after police used tear gas.

The man was taken into custody without incident and police recovered a handgun, Amtrak spokeswoman Christina Leeds said.

The train carrying 187 passengers and five crew members was evacuated Friday night after several reported seeing a man with a weapon acting erratically. The train bound for San Diego was stopped in the San Fernando Valley area of Los Angeles as police conducted a search.

"Someone reported that he dropped a gun -- likely was then reported to the train folks -- and that's when things escalated," passenger Allison Bird told KABC-TV in Los Angeles.

The standoff ended nearly eight hours later after tear gas was deployed, according to the Los Angeles County Sheriff's Department.

The department tweeted a photo of a man in handcuffs wearing a cap, green shirt and shorts.

Amtrak identified the man as 46-year-old Oxnard resident Darius Palmer. He was charged in Los Angeles Superior Court with making terroristic threats and felony possession of a firearm, Leeds said.

It was not immediately known if Palmer has a lawyer.

Firearms are prohibited in carry-on bags, according to Amtrak policy. Passengers can check rifles, shotguns and handguns if they meet certain requirements, including notifying the rail agency beforehand, unloading the weapons and storing them in locked containers.

The standoff forced temporary delays of commuter trains that share the same tracks. Buses shuttled the evacuated passengers to other train stations.

Amtrak canceled two trains Saturday as the investigation continued.