Ashley Jensen will also star in the drama, which will be filmed in and around Glasgow and Ayrshire this autumn.
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.
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.”
Mayflies will air on BBC One, BBC Scotland and BBC iPlayer with a release date yet to be confirmed.