Dupree Kenneth Hornsby is charged with rape of a child and other felonies for the attack reported at 7:36 a.m. Friday in the 100 block of Damsen Drive.
According to the Santa Clara County District Attorney's Office, the girl was playing in her home when Hornsby allegedly entered, locked her in a room and sexually assaulted her. When he eventually let her go, she ran to a family member and Hornsby fled.
RELATED: French Bulldogs returned to owner after San Jose Police make large crime bust
At about 9:10 a.m., an officer saw a man walking in the area matching a description given of the suspect and detained him. The man, later identified as Hornsby, was eventually booked into the Santa Clara County Main Jail, San Jose police said.
"This nightmare of a crime has shaken all of us," District Attorney Jeff Rosen said in a statement. "The alert police officer who saw and arrested this predator just hours later, and before anyone else was hurt, is a credit to the badge and our community."
Anyone with information about the case is asked to call Detective Yue or Detective Sgt. Marquardt of the Police Department's sexual assaults investigation unit at (408) 277-4102.