The victim had been followed by Peter Robinson as she walked the street at around 11.30pm one night in 2021.
Newcastle Crown Court heard the woman had noticed Robinson as she passed him but then heard the chilling sound of footsteps behind her.
During a terrifying ordeal the victim was dragged into a dark lane, ended up on the ground, her shoes came off and she suffered an injury to her leg.
See 11 fantastic pictures from the Seaham Food Festival as thousands of foodies head to the coast
Thousands of foodies hit the coast for Seaham Food Festival featuring Masterchef star Pookie Tredell and Sunderland's Life Kitchen founder Ryan Riley
Tyne and Wear Fire and Rescue Service praises 'incredible response' of crews 'working through the night' at barn blaze
Family of Archie Battersbee vow to call for ‘change’ after his death
Overturned vehicle reported on A19 access road near Castle Eden Junction
Fortunately, a passing motorist, who had music playing and friends in the car, was able to hear her screams over the traffic noise, stopped his vehicle and stepped in to apprehend Robinson.
The victim was described as being as "white as a sheet" and "in total shock" after the attack.
The court heard Robinson, who had been taking drugs, was using an electric cable to hold up his trousers which had snapped and left his private parts exposed.
Miss Recorder Caroline Goodwin QC awarded the passer-by £100 from public funds for his brave intervention.
Robinson, 35, of Salem Hill, Sunderland, who has previous convictions, admitted attempted robbery and has been jailed for six years and nine months.
The judge said what happened must have been "harrowing" for the victim and told Robinson: "You made the decision to follow her. She described hearing the footsteps behind her which, for a lone woman late at night, cannot be underestimated in any way.
"Not only was she attacked but you physically took hold of her by her coat and effectively dragged her into the alleyway.
"You knocked her to the ground. One can only imagine what was going through her mind at that time of night.
"Her shoes came off, her leg was injured and she began to scream. Her screams were heard and acted upon.
"The fact she could see your penis exposed, in part because you were such a dishevelled mess, meant she thought the attack was going to be be far more serious than fortunately it transpired."
The court heard Robinson has engaged with services to help overcome his drug addiction and deal with his diagnosed mental health problems.