There are two first-person narrative voices in Sebastian Barry's new novel, The Secret Scripture, and both of them are trying, in their different ways, to make sense of the past - their own and their country's. The first, and most moving, belongs to Roseanne, an Irish woman who is 100 and who has spent most of her adult life in the Roscommon Regional Mental Hospital, which is just about to be closed down. Throughout her confinement, Roseanne has written her life story, the 'secret scripture' of the book's title, a clandestine act of testimony and reclamation. 'I am completely alone,' she says, early on. 'There is no one in the world that knows me outside of this place... I am only a thing left over, a remnant woman...'

The person who perhaps knows Roseanne best, but then only barely, is Dr Grene, the other narrative voice. He is the psychiatrist who must now prepare her for the emotional upheaval that the hospital's imminent closure will precipitate. The more Dr Grene learns about Roseanne, her young life, and her reasons for being under his care, the more he admires her resilience, her quiet fortitude, her lack of bitterness. The more, too, he begins to uncover the buried history of Ireland in the last century, a country in which there were thousands of Roseannes, women who were 'disappeared' into asylums and convents when they fell pregnant outside wedlock or were abandoned by their husbands.

This, by now, is familiar territory for Irish writers, both of fiction and memoir, but Barry illuminates it anew by interrogating, through these two intertwining, and often contradictory, narratives, the nature of memory - and of writing itself. 'The true unreliability of everything written down utterly fascinates me,' he says when I meet him in the lounge of the Merrion Hotel in Dublin, where we sit among whispering politicians from the nearby Dáil building. 'Even the person who has set down the so-called facts the most dispassionately, the most accurately, the most believably, will still get it essentially wrong.'

Barry, a dapper dresser who looks like he might be related to WB Yeats, is a great interviewee. He tends to talk as he writes, in sentences full of beautiful imagery. 'History,' he says, 'has always seemed to me to be an intoxication of facts and it is in the ever-present ruins of history that I work.'

It is in these ruins, he explains, that he found Roseanne, who is based somewhat tangentially on one of his great aunts, who similarly disappeared into an institution, having somehow transgressed the rigid codes of Catholic Ireland. In one way, The Secret Scripture is a final breaking of the long familial silence that enshrouded her. 'I once heard my grandfather say that she was no good,' says Barry. 'That's what survives and the rumours of her beauty. She was nameless, fateless, unknown. I felt I was almost duty-bound as a novelist to reclaim her and, indeed, remake her.'

This excavation of his own family history to underpin his stories is not without its risks. His play, Our Lady of Sligo, based on tales his mother told him of his grandmother's life, utterly incensed his grandfather. 'He summoned me and asked me how I knew all these things,' says Barry, grimacing now at the memory. 'Then he cursed me and told me he would never speak to me again. He's gone now but he was as good as his word.'

Barry, who lives in the Wicklow countryside, has already made a name for himself as a writer who negotiates the traumas of Irish history and identity through the often-blighted lives of his Everyman characters. Until he was shortlisted for the Booker Prize in 2005 for his novel A Long Long Way, his best-known work was The Steward of Christendom, a play that became a hit both here and on Broadway. It centred on Thomas Dunne, a Dublin policeman loyal to the Crown in the tumultuous years that led to the Easter Rising in 1916. His son, Willie Dunne, a soldier in the Royal Dublin Fusiliers at the time of the Rising, is the protagonist of A Long Long Way, in which the same theme of divided loyalty is played out against the bloody backdrop of the First World War. 'I am trying to rescue my characters from the cold hand of history,' says Barry, 'and from the silences that surround certain turbulent periods in our own history.'

There is a similar kind of creative slippage in The Secret Scripture, in which Roseanne's absent husband Thomas McNulty is the brother of the main character in another of Barry's previous novel, The Whereabouts of Eneas McNulty. In all Barry's fiction, there is a very real sense not just of the cruel sweep of history but of the fallout from smaller dramas: family fractures, local quarrels, tribal loyalties. 'I think the Dr Grene character sees that most clearly,' says Barry. 'He has the required distance, being an Irishman and somehow not, and having grown up elsewhere and then come back. He knows there is nothing he can do for Roseanne that would help her more than what she has done for herself in the very act of writing'.

The Secret Scripture is a book that, despite the lyrical beauty of Barry's prose, may stand and fall for some readers on the dramatic plot twist that occurs late in the story, and which, like the similar revelation in Philip Roth's The Human Stain, alters the impact of all that has gone before. I was not entirely convinced myself, but was so taken by the cumulative power of Roseanne's often unreliable testimony that it hardly mattered. This is a book that is essentially about the haziness of history and the ways in which memory can help rescue us from the past by allowing us to reimagine it. A kind of Freudian history of Ireland, then.

It is also a book that, like life, is peopled by strange, often ghostly, minor characters, whose impact on the two main characters is far-reaching. This being an Irish novel of remembering, the most unsettling is a priest, the aptly named Father Gaunt, an unwittingly cruel man in thrall to his own power, a pious meddler in the lives of others.

'For a long time, all I had was this image of him swishing though the streets of Sligo, bringing morality house to house,' laughs Barry, before turning suddenly serious. 'In many ways, he is an arbiter of the thing that terrifies me most, the absolute certainties of Irish history.'

And it is those absolute certainties that Barry writes against. He tells me, in passing, of a real priest he once knew who introduced him to Maupassant at school. 'He had all my books by his bedside when he died,' he says, shaking his head and sighing. 'But he was also being proceeded against in some way by various concerned parents for something he may or may not have done.' He pauses for a moment. 'It's a complicated place, the past, and the writing I do is deeply suspect in some way. And yet the enterprise of taking it upon yourself to write down anything meaningful, as long as it is not done out of revenge, is an act of homage in some way.'

· The Secret Scripture is published by Faber, £16.99. To order a copy for £15.99 with free UK p&p, go to observer.co.uk/bookshop or call 0870 836 0885