The incident began at about 1:55 p.m. in the 500 block of Valencia Street, when police responded to a report of a person with a gun, according to police.
Police attempted to negotiate with the suspect, but they refused to come out.
By about 9:05 p.m., the suspect stepped into the building's hallway and was taken into custody. The suspect was then taken to a hospital for evaluation, police said.
Afterward, the police's Special Operations Bureau checked the apartment for weapons and anything that may have been hazardous.
Valencia Street was closed between 16th and 17th streets, and residents had been asked to shelter in place. Valencia Street is set to reopen and the shelter in place is being lifted, according to police.
The initial call came in after someone doing pest control work in the building went to an apartment. The apartment's resident then pulled out a gun and the exterminator fled, police said.
Stay with ABC7 News for more updates on this developing story.