The intercourse, which occurred without a contraceptive, took place in the third-floor toilets, the court heard.
Afterwards, the girl told Mahy it was her birthday the next day and she would give him "a free one".
They met the following day at the same time, with the same result.
Mahy gave the victim $20 and they went their separate ways.
Crown prosecutor Craig Power said the public nature of the sex offences was particularly "brazen" and he highlighted the vulnerability of the teen.
She suffered a disorder characterised by "markedly disturbed and inappropriate ways of relating socially in most contexts".
Since the incident, Judge Michael Crosbie said, the girl's family had noticed significant changes in her behaviour.
The victim had begun self-harming, had run away from home and become increasingly isolated.
She had the mental age of a 9-year-old, the judge said.
A psychologist's report on Mahy assessed him as unmotivated to address his offending.
Mr Power said it was also concerning that he was seen as impulsive and showed disregard for the wellbeing of the victim.
However, defence counsel Cate Andersen said her client had misunderstood some of the questions asked of him in the interview.
He had shunned any suggestion of treatment because he did not consider himself "predatory", she explained.
Since the matters had been clarified, Mahy was now willing to undertake any programmes in prison for sex offending.
Andersen called the acts "opportunistic" and underscored parts of the report which found no evidence of sexual deviance on the defendant's part.
However, Judge Crosbie rejected that characterisation, given there were two incidents.
He noted Mahy had been sentenced to community work for unrelated offending less than a week before the library liaisons.
While the defendant had held down jobs and was regarded as hard working, he had a history of abusing alcohol, the court heard.
Mahy was sentenced to three years two months' imprisonment and will be added to the Child Sex Offenders' Register.