Judge Lord Uist described 36-year-old William McArthur’s crimes against the child as “unspeakable, indeed incomprehensible evil”.
He encouraged a woman to send him topless pictures as his young victim lay in a critical condition in hospital.
McArthur inflicted numerous injuries on his victim, carrying out horrific sexual abuse during a catalogue of crimes against women and children committed between 2014 and last year.
At Edinburgh High Court Lord Uist told McArthur he had demonstrated he was “a serious danger to any women and children with whom you come into contact”.
He raped a woman and a teenager and sexually assaulted another woman as well as committing acts of violence against three children.
McArthur’s defence counsel, Donald Findlay QC, unsuccessfully urged the judge to deal with him by imposing a determinate sentence followed by a period of supervision, arguing “he is not a man with an inherently dangerous criminal past”.
But Lord Uist told McArthur he was imposing imprisonment on him for an indeterminate period under an Order for Lifelong Restriction.
He must serve a minimum jail term of seven years before he becomes eligible to apply for parole, but cannot assume he may be released after that period.
McArthur has also been placed on the sex offenders register indefinitely.
The court heard the former West Lothian college student was previously jailed for 27 months for carrying out assaults on three different women.
He had denied a series of charges but was convicted of nine crimes.
These included attacking a six-year-old girl in 2014 at a caravan in Dumfriesshire, and raping a 14-year-old girl at a house in Grangemouth after she had been drinking and was sick in 2017.
A spokesman for NSPCC Scotland said: “This is a disturbing case which saw McArthur inflict appalling abuse and injuries on a defenceless four-year-old girl and commit a string of crimes on children and women.”
“He clearly poses a serious risk to children and it is right that he will face the consequences of his horrific crimes.
“Young children are completely reliant on others so we all have a responsibility to look out for their welfare.
“NSPCC Scotland works in schools and in the community to prevent abuse and anyone worried about a child can contact our Helpline to report concerns.”
Any adult concerned about the welfare of a child or young person can call the NSPCC helpline free, 24 hours, on 0808 800 5000.
Children can call Childline at any time on 0800 1111.