The novel explores a friendship that starts in the summer of 1986 when Jimmy (Martin Compston) and Tully (Tony Curran) bond over music, films and the rebel spirit.
The “nostalgic, poignant and moving” story examines what happens to the friendship when it is put to the test after the phone rings with unexpected news 30 years later.
Mayflies is a co-commission with BBC Scotland and will be made by the Bafta-award winning Synchronicity Films for the BBC.
O’Hagan said: “For a while now, I’ve admired the work of Synchronicity Films – Scottish in its bones and international in complexion – and it’s a thrill to see them bringing Mayflies to BBC One.
“The story is a very personal one to me, and it’s amazing to see the characters come to life in Andrea Gibb’s wonderful adaptation.
“Director Peter Mackie Burns has a singular vision, and I look forward to seeing what he makes of the Ayrshire landscape and the emotional reality of this story.”
Jensen plays Tully’s partner Anna in the mini-series, which is being made for the BBC in association with All3 Media International, with support from Screen Scotland.
Gaynor Holmes, BBC Drama commissioning editor, said: “We’re incredibly proud to continue the BBC’s longstanding commitment to showcasing the very best of Scotland and Scottish talent with this distinctive new drama.
“Mayflies is an intimate and devastating portrait of male friendship that manages to be both life-affirming and heart-breaking, and we’re delighted to have assembled an outstanding lead cast and creative team to bring it from page to screen.”
Gibb said adapting the novel for the screen has been one of the highlights of her career.
She said: “Andrew tells his story of enduring male friendship with love, truth, tenderness and a searing humanity. There’s not an ounce of sentimentality.
“It’s very funny and deeply moving. The characters of Tully and Jimmy are instantly recognisable and totally unforgettable.
“Both are so alive and vibrant they leap off the page. It’s been a joy and a privilege living with them.”
Mayflies was named the Waterstones Scottish Book of the Year 2021 in November.
Claire Mundell, executive producer, founder and creative director of Synchronicity Films, said: “Andrew’s novel is nostalgic, poignant and moving, following a life-long friendship and exploring the optimism of youth and the realities of later life.
“It honestly depicts the bonds and boundaries of a shared life and values.
“We are excited to be working with Andrew, Peter, Andrea and the BBC to collaborate on an authentic scripted adaptation of this acclaimed Scottish novel.”
Mayflies will air on BBC One, BBC Scotland and BBC iPlayer with a release date yet to be confirmed.