The complex was evacuated after police received a call at 10 a.m. about a person creating a disturbance at the Cypress Pointe Apartments at 8200 Kern Ave., Gilroy spokesman Joe Kline said.
Police ordered the evacuation of the complex and isolated a specific apartment after witnesses indicated that the person inside might have a bomb and firearms, Kline said.
A SWAT team and other negotiators tried to convince the person to exit the apartment and the standoff finished with the suspect in custody at about 4:15 p.m., Kline said.
No one was injured.
Officers from the Morgan Hill Police Department and the Santa Clara County Sheriff's Office also responded to the scene, Kline said.
Traffic was blocked on Kern Avenue between Welburn Avenue and First Street, and a two-block area around the scene was cordoned off, Kline said.
A shelter for evacuees was set up at the Gilroy Senior Center at 7371 Hanna St. in Gilroy.
As of shortly after 5 p.m. police were checking the apartment where the suspect was barricaded to make sure there was no further threat and planned to let residents back into the area once it was cleared, Kline said.