Conor Bull, 17, from Stranraer, raped the schoolgirl in December last year and later boasted of what he had done to a friend.
At the High Court in Glasgow, judge Lord Burns told Bull: "The public interest does not require a custodial sentence."
Instead Lord Burns ordered Bull to perform 101 hours of unpaid work in the community.
The judge told Bull that, but for his early plea of guilty, he would have ordered him to perform 150 hours' community service.
Bull will also be under the supervision of a social worker for three years and attend a course designed to make sexual offenders realise the impact their actions have had.
The court was told that Bull believed the girl was 16 and her Facebook pages where she had claimed to be 14 were shown to Lord Burns by defence counsel Simon Gilbride.
Mr Gilbride said: "Mr Bull says she told him she was 16 coming on 17 and there were entries on Facebook and Bebo where she seemed to give different ages."
The court heard how Bull had been with the girl and others last December 30 before going to his Stranraer home. He later went into a bedroom with the youngster and asked "did she want to do it". The pair had sex before the girl returned to her home with a friend.
The incident came to light when the girl went to hospital complaining she felt sick.
Lord Burns told Bull: "You should take this opportunity I'm giving you."