John Fawcett,26, used the social media networks to groom the girl before assaulting her at a location in Leslie, Fife, on 4 October 2016.
The High Court in Edinburgh heard how Fawcett had made contact with the teenager when she was aged 16.
The court heard Fawcett “flirted” with the girl in the weeks leading up to the attack. He sent her pictures of his private parts and arranged to meet her at a secluded spot.
The girl, who cannot be named for legal reasons, agreed to meet him, but the court heard she did not consent to having sex with Fawcett.
Judge Lord Brailsford yesterday told Fawcett, who served with the Royal Electrical and Mechanical Engineers, he had no other option but to send him to prison.
He said: “I take into account the fact that you have served your country. However, you have been convicted of a very serious offence.
“I must mark the seriousness of this offence by imposing a prison sentence. It will be one of five years.”
Lord Brailsford also placed Fawcett on the Sex Offenders’ Register.
Fawcett, also of Leslie, was convicted of rape following a three-day trial at the High Court last month.
Known in his home village as Rob, Fawcett had pleaded not guilty to the charge. Jurors took just two hours to return a majority guilty verdict.
During proceedings, the court heard how the girl, who is now aged 18, made contact through social media. The young woman told prosecution lawyer Jim Keegan QC the pair flirted with each other over the social media networks. They agreed to meet up with each other at the Back Braes in Leslie.
She told the court once she met up with Fawcett, he started indulging in sexual activity that she did not consent to.
The young woman told the jury Fawcett forced her to the ground before starting to kiss her. He then restrained her and performed sex acts on her before pulled her legs over her head and raping her.
The young woman later told a friend about what happened before telling her grandmother about the rape.
She contacted police who managed to gather enough evidence to bring Fawcett to justice.