Michael Shaw entered the home in Ormskirk at around 1.15am before he was disturbed by the occupants on February 22.
He was then seen touching him inappropriately outside the address, officers said.
Following a police appeal, Shaw, of Railway Path, Ormskirk, was jailed for 30 months for trespass with intent to commit a relevant sexual offence Imprisonment.
The 30-year-old appeared at Preston Crown Court this week for sentencing after pleading guilty at an earlier hearing.
He was also given eight week and 10-week sentences for exposure, to run concurrently, ordered to sign the sex offenders register and given a 10-year Sexual Harm Prevention Order.
Det Sgt Di Higham, of South Police, said: "I welcome this sentence which reflects the gravity of the offending and I would like to thank the community for their help and co-operation following this disturbing incident."
Support us and become a subscriber today. Enjoy unlimited access to local news, the latest football stories and new puzzles every day.
With a digital subscription, you can see fewer ads, enjoy faster load times, and get access to exclusive newsletters and content. Click HERE to subscribe.