An armed woman barricaded herself inside a residential hotel in San Francisco’s Mission District for seven hours Friday, before surrendering shortly after 9 p.m., police said.

Police had been talking to the woman for about 2½ hours when “she stepped into the hallway and was taken into custody,” said Sgt. Michael Andraychak of the San Francisco Police Department. She was taken to a hospital for evaluation, he said.

The incident, which police said caused them to close busy Valencia Street and bring in a negotiating team, was reported just before 2 p.m. at the Crown Hotel at 528 Valencia Street, near the Mission District Police Station.

The standoff started inside the residential hotel when a person going “door to door in the building doing pest control services” was greeted by a woman with a gun, Andraychak said.

The victim, who was not identified, was able to escape unharmed, Andraychak said, but the armed woman then set up a barricade inside a room on the second floor. Police negotiators establish voice contact with her about 6:30, and by 8 p.m. officers were talking to her from the hallway in the hotel.

Andraychak would not identify the armed woman but said she was “known” to police.

Valencia Street was closed between 16th and 18th Streets as a SWAT team and negotiators were brought in to try to contact the barricaded woman, said Officer Robert Rueca, a spokesman for the San Francisco Police Department.

No shots were initially fired, Rueca said. Dozens of officers surrounded the area and later pushed the street closures back both east and west on 16th Street. People in surrounding buildings were ordered to shelter in place.

Rebecca Pierce, 27, who was dining at Thanh Tam Il Restaurant in the 500 block of Valencia Street across from the incident, said at first police told her and other patrons to stay inside the restaurant.

About half an hour later, police officers re-entered the restaurant to tell her to evacuate because the restaurant was in the “line of fire,” sending Pierce running toward 17th Street, she said.

“The only time I really feared for my safety was when I had to enter the street unprotected,” she said. “I’m shell shocked and still processing what happened, but I’m doing OK.”

No injuries were reported, and it wasn’t immediately clear what caused the confrontation, Rueca said.

The Crown Hotel was acquired by the Tenderloin Housing Clinic in October and is part of the Department of Homelessness and Supportive Housing’s portfolio of buildings that provide transitional housing. Of the 55 units in the building, 30 are set aside for homeless veterans.

Tenderloin Housing Clinic Executive Director Randy Shaw said that the barricaded woman already resided in the hotel when his group took it over.

He called the long episode “an enormous inconvenience” for residents.

Michael Bodley and Filipa Ioannou are San Francisco Chronicle staff writers. Email: mbodley@sfchronicle.com and fioannou@Sfchronicle.com. Twitter: @michael_bodley and @obioannoukenobi