Over the course of my writing life, I’ve often been asked why I don’t set my novels in Ireland. To this question, I had a stock reply: that I didn’t want to write about my own country until I had a story to tell. Now, having written a book that takes the subject of child abuse in the Irish Catholic church as its theme, I wonder if that answer was entirely honest.

I’ve spent the past two years recalling experiences from my childhood and teenage years that I would rather forget, reliving events that should never have taken place and recreating through fiction, moments that seemed small at the time but that I’ve come to realise caused me great damage. Which makes me think that the real reason I never wrote about Ireland until now is explained in the opening sentence of my novel:

“I did not become ashamed of being Irish until I was well into the middle years of my life.”

When I was growing up in Dublin in the 70s and 80s, the parish priest lived in the house to my left while eight nuns lived in the house to my right. I was an altar boy, went to a Catholic school and was brought to mass every Sunday. I knew there were Protestants in Dublin, and Methodists and Jews and Mormons, but I never laid eyes on any of them, and probably would have run a mile if I had. They were going to hell, after all, or so the priests told us. And as long as we learned our catechism by heart and lived good Catholic lives, we were not.

The importance of church life in my parish during this era cannot be overstated. For a family not to attend mass would have been to invite immediate exclusion from social circles. To have a priest to dinner was the dream, and if it happened, preparations would take place for weeks in advance. They say the Queen thinks the world smells like fresh paint. Well the priests did too. The whole house needed a makeover before he came for his tea. And yet, for all the sycophantic behaviour that went on, it was rare to find true believers. Everyone knew which priests offered the shortest masses and the briefest sermons, and no one ever told the truth at confession. I remember thinking that if I said what was really going on in my head, I would probably be excommunicated, arrested or both. And so I did what everyone else did: I made stuff up. Ordinary, decent sins.

John Boyne on the day of his communion with his younger sister.

I was a quiet, shy and well-behaved child and yet somehow, whenever I found myself in trouble, it was with the priests. As an eight-year-old altar boy, I was so terrified by the consequences of having shown up for the wrong mass that I broke down in tears on the altar and had to be carried off. It sounds funny now but I can still recall the absolute panic at what would happen to me. I don’t think I’ve ever been so frightened, before or since.

At 13, I had the misfortune to be taught by a sadistic priest who carried a wooden stick up his sleeve with a metal weight taped to the end of it. He called the stick Excalibur and once beat me so badly that I was off school for two weeks. The pleasure he took as I crumbled before him was obvious.

Another priest conducted “fair trials”, where a boy – often myself – would be brought to the front for some infraction, tried by his classmates, inevitably found guilty and have his pants pulled down in front of everyone for a spanking.

But it wasn’t just the priests. Lay teachers, fully aware of the accepted practices of their religious employers, could also be responsible for unpleasant acts. A teacher stood over my shoulder as I worked and reached his hand down the front of my trousers, keeping it there long enough for him to get his kicks before moving on to the next boy.

These things and more happened all the time and we never uttered a word of protest. We felt they had the right to do what they wanted because they wore a collar. And they wonder now why my generation has so little respect for them.

Once puberty and an independent mind kicked in, I began to feel more hostility towards the church. It’s not easy to be a young, gay teenager and to be told that you’re sick, mentally disordered or in need of electroshock therapy, particularly when you hear it from someone who groped you on your way to class the day before. I doubt any of them understood how, as they preached love and practised hatred, they blighted my youth and the youth of people like me, leading to the most unhealthy and troubling relationships once I became sexually active.

Problems I have suffered in my life with depression – which have been ongoing and multitudinous and chemically alleviated – I put down to the fact that my priests and educators made me feel worthless, and disparaged and humiliated me at every turn. Which is ironic, considering that in all other facets of my life I had an extremely happy childhood.

John Boyne aged five.

Throughout my youth, as Pope John Paul II travelled the world in luxury, playing on his popularity to reinforce concepts that were not only outdated but also destructive and harmful, he basked in the applause of young people while making sure to cover up every single crime that was committed against them. And still, in behaviour that beggars belief, tens of thousands of people, many of them under 30, poured into St Peter’s Square earlier this year to celebrate his sanctification. Where is their compassion? Where is their humanity? And the more scandals that came to light over the years, the more I grew convinced that there was not a single good man to be found among their number and the sooner they disappeared from our lives, the better it would be for all.

When I started publishing novels 15 years ago, I knew that I couldn’t write about this until I was experienced enough to do so. And then one day a relation told me that he had seen a young priest lying prostrate before the grotto of Inchicore church, weeping hysterically, while a woman – apparently his mother – sat nearby in equal distress. Why he was there, I do not know, but I found myself greatly affected by the image. Was he a criminal, I asked myself? Probably. But how had he suffered when he was young? What had brought him to this place of personal devastation? And to my astonishment, I began to feel something that I had never expected to feel towards a priest: empathy.

A novelist looks for the stories that haven’t been told. It would be very easy to write a novel with a monster at the centre of it, an unremitting paedophile who preys on the vulnerable without remorse. The challenge for me was to write a novel about the other priest, the genuine priest, the one who has given his life over to good works and finds himself betrayed by the institution to which he has given everything. In doing so, I was trying to uncover goodness where I had spent a lifetime finding evil.

I interviewed many priests who will not venture out while wearing their habits in case they are spat at; others who are terrified of finding themselves alone with a child in case they are wrongfully accused. Their pain, and their compassion for the victims of abuse, moved me and forced me to confront my own prejudices.

In writing this novel I hoped that those who blindly defend the church against all critics might recognise the crimes that the institution has committed, while those who condemn it ceaselessly might accept that there are many decent people who have lived good lives within it. It’s a story that Irish writers have for the most part ignored but it’s not written in defence of the church – indeed, by the end of it, the reader has to consider the narrator’s complicity in the events that were taking place before him – but nor is it an outright attack. It is simply a novel that asks people to examine the subject from a broader perspective and to reconsider the lives of all those who have suffered, both within and without one of the fundamental pillars of Irish society.

• To order A History of Loneliness by John Boyne for £11.24 (RRP £14.99), go to bookshop.theguardian.com or call 0330 333 6846