Despicable John Slater (55) was just 13-years-old when he started abusing a nine-year-old girl in June 1975.
Edinburgh Sheriff Court heard on Friday how the abuse against the woman, who cannot be named for legal reasons, took place at various locations in Midlothian.
The court heard how the abuse against the female only stopped in June 1982.
Slater, who has no previous convictions, sexually assaulted his second victim between October 1986 and October 1987 at addresses in the Edinburgh area.
The woman, who also cannot be named for legal reasons, was aged just 14 when Slater started targeting her.
Slater was convicted of sexual assault charges last month at the court. Sentence had been deferred for the court to obtain reports.
On Friday, Sheriff Thomas Welsh QC told Slater he had no other option but to send him to prison.
He added: “You must have known what you were doing was wrong. The only sentence I can impose in this case is one of custody.”