Robert Hugel, 26, of Hartley Street, Boston, was disturbed by a witness who had been keeping an eye on the intoxicated woman from her bedroom window.
Lincoln Crown Court heard the witness first became aware of the victim shortly after 4am on Sunday, August 1 after she was woken by screaming.
David Outterside, prosecuting, said the witness looked out of her bedroom window in Silver Street and noticed the woman lying on the ground.
“She was lying on her back, mumbling and groaning,” Mr Outterside explained.
Mr Outterside said the witness continued to keep an eye on the woman, and noticed two other people checking on the woman before leaving her on her own.
A short time later the witness heard what she thought was an East European voice speaking to the woman in broken English.
“He was telling her he was going to help her, that she needed to go home.”
Mr Outterside said the witness continued to check on the woman, and noticed her clothing had been pulled down and her buttocks were exposed when she looked out of the window again.
She also noticed the defendant’s trousers had now been pulled down and his buttocks were exposed, with him positioned behind the woman.
Mr Outterside said: “The witness shouted to her partner, ‘I think he is going to rape her,’ and thankfully ran into the street dialling 999.”
Hugel left the scene and was later tracked to his home. He pleaded guilty to an offence of attempted rape on August 1, this year.
Mr Outterside said the victim appeared drunk and could not stand on her own.
She later told police she had no memory of the incident.
Mr Outterside said: “In total the defendant was with the victim for around ten minutes.”
The court heard Hugel, who listened to the hearing via a Romanian interpreter, first came to the UK in 2017 and had no previous convictions.
Tara McCarthy, mitigating, said Hugel could not explain his actions after initially going to help the woman.
Miss McCarthy added Hugel was remorseful and struggled to reconcile what he had done.
Passing sentence Recorder Ruth Coffey told Hugel: “At some point you decided to take advantage of this woman’s vulnerability.”
The Recorder added it was a great credit to the witness that she ran out into the street and stopped the incident.
Hugel must also register as a sex offender for life.
Detective Inspector Gemma Smith said after the sentencing: “We would like to, first and foremost, pay tribute to the victim. She has been deeply distressed by the incident and incredibly brave in her support for the investigation.
“The details of this case are chilling and it was right that we should treat it with the seriousness it deserved. Our team worked tirelessly to identify the suspect and build a portfolio of evidence against him. I hope that at least brings some comfort to the victim and to the community.
“Hugel was identified swiftly, charged and remanded within two weeks of the offence. I would like to thank the officers involved in making sure this happen, and the public who provided witness statements and information. This is a rare occurrence, but something that should never happen. We hope the case serves as a deterrent to offenders and a reassurance to our communities that we will relentlessly pursue offenders.”