Click here if you are having trouble viewing video on a mobile device.

SAN JOSE — A man was arrested on suspicion of sexually assaulting and robbing an unsuspecting teacher at Harker Middle School earlier this week after apparently trying to stall police officers closing in on him by offering to surrender, which authorities say was a ruse to allow him to get out of town.

Andrew Bracamonte, 23, of San Jose, was taken into custody Thursday night, two days after the attack was reported at the West San Jose school, police said. The San Jose Police Department’s covert response unit had an arrest warrant in hand and was monitoring the man when a third party contacted police to arrange a surrender for 10 a.m. Friday morning.

Get breaking news with our free mobile app. Get it from the Apple app store or the Google Play store.

Thursday evening, the police unit ended up following Bracamonte, who lives near Harker, as he was driven by a female acquaintance up the Peninsula to San Francisco, where he was arrested around 7:55 p.m. When he was taken into custody, police say Bracamonte had altered his appearance, including cutting his hair, indicating to them that he had no plans for surrender and was buying time to flee the area.

“The suspect did not give the victim a choice, and we certainly were not going to allow the suspect to dictate how we were going to take him into custody,” police Chief Eddie Garcia said. “He must have thought we were idiots that were going to walk away and wait for him. He cut his hair. These were not the actions of someone who was going to surrender.”

Garcia said a contingent of nearly 50 officers worked on the case from start to finish, including a K-9 unit that tracked Bracamonte’s scent to a neighborhood about a quarter-mile away where he presumably lives. Surveillance footage from the school, and in other spots in Santa Clara and San Jose where he went afterward, also helped detectives track him down.

“Just an amazing job by the men and women of this organization,” Garcia said.

Bracamonte was booked into the Santa Clara County Main Jail on suspicion of robbery, false imprisonment, forced oral copulation, criminal threats, and assault with the intent to commit a sexual assault during the commission of a burglary. He is being held on $500,000 bail.

The chief commended the bravery of the assault victim for being a good witness for them after enduring a harrowing encounter where police say the suspect snuck into the classroom, locked the door, turned off the lights, and attacked her. After taking her phone, police say the suspect threatened to kill her if she left the classroom afterward. Garcia dismissed social-media remarks he had seen criticizing security measures at the school.

“The strength of the victim in this case can’t be forgotten,” he said. “Only one person is responsible for this heinous crime, and he’s in custody.”

According to police, Bracamonte has a criminal record in San Jose that includes arrests on suspicion of assault with a deadly weapon, carrying a concealed weapon or dagger, having sex with a minor, drug possession, and violating his probation. However, he was not on parole or probation when he was arrested Thursday, and is not a registered sex offender.

Harker officials welcomed news of the arrest.

“We are grateful for the hard work of the SJPD, and the support of the media and the greater community, that resulted in an arrest today,” said Head of School Brian Yager. “This was a senseless, heartbreaking crime and our entire community is grieving. We are relieved that this criminal has been arrested, and hopeful that justice will be served.”

The female teacher was attacked around 6 a.m. Tuesday in a classroom on the campus at 3800 Blackford Ave., about a half mile from the intersection of Moorpark and Saratoga avenues, school officials said. Students typically arrive between 7 a.m. and 8 a.m., and were set to resume classes after the holiday break.

Responding officers and investigators found the victim’s cell phone and a beanie cap believed to belong to Bracamonte in a nearby field. The cap was used to train a police dog on the suspect’s scent, police said. Other clues and tips led police to a liquor store in the Santa Clara city limits, and surveillance footage showed that Bracamonte had been there later Tuesday and committed an undisclosed minor crime.

Helping investigators connect the dots was how the suspect in multiple surveillance videos exhibited a distinct walk. They also recovered unspecified evidence that linked him to both the school and the liquor store.

Investigators said there was no evidence indicating any connection between the victim and the suspect.

“We believe it was a random attack,” Garcia said.

Like our Facebook page for more conversation and news coverage from San Jose, the Bay Area and beyond.

In the wake of the assault, police dispatched multiple school-liaison officers to the middle school, and increased patrols around the school and in the surrounding neighborhood.

Anyone with information about the case can or contact Detective Sgt. Samantha Huynh or Detective Jennifer Majors of the SJPD Sexual Assault Investigations Unit at 408-277-4102, or leave a tip with Silicon Valley Crime Stoppers at 408-947-STOP or svcrimestoppers.org. Tipsters may be eligible for a cash reward.

Staff writer Mark Gomez contributed to this report.