The ghostwriter who collaborated with Julian Assange on his abortive 2011 autobiography has broken his silence to describe his months working with the WikiLeaks founder, which culminated in the acrimonious collapse of one of the highest profile and most lucrative book deals of recent times.

Three years after he was first introduced to the Australian, Andrew O'Hagan has now spoken out about how he worked with Assange on the book, which he said the publishers Canongate had sold in more than 40 countries for a total of US$2.5m before the deal dramatically imploded. In a lengthy, nuanced essay for the London Review of Books, a version of which he delivered in a lecture in London on Friday, O'Hagan describes working with a mercurial character who was, by turns, passionate, funny, lazy, courageous, vain, paranoid, moral and manipulative.

The book deal ultimately collapsed, O'Hagan writes, because "the man who put himself in charge of disclosing the world's secrets simply couldn't bear his own. The story of his life mortified him and sent him scurrying for excuses. He didn't want to do the book. He hadn't from the beginning."

Assange, he writes, was persuaded to agree to the autobiography by his lawyers who said the huge sums on offer would cover his mounting legal costs. He had initially been enthusiastic about the project, telling his ghostwriter that he "hoped to have something that read like Hemingway", and suggesting ever more avant garde styles for the book to take, such as writing the first chapter with one word, the second with two, and so on.

But O'Hagan reveals that as the deadline to deliver a manuscript approached, Assange was "totally shocked" at the prospect of his own story being told, describing people who write about their family as "prostitutes".

Exasperated at their author's non-co-operation and hoping to reclaim a proportion of their significant stake, Canongate published a version of O'Hagan's manuscript as Julian Assange: The Unauthorised Biography in September 2011 without the Australian's consent.

Though Assange denounced its publication, he told O'Hagan that he was covertly encouraging sales and tweeting links to its Amazon page. That strategy failed: despite its huge advance and publicity, the book sold fewer than 700 copies in its first week, a spectacular publishing failure.

O'Hagan, an award-winning, Booker-nominated novelist and non-fiction writer, was brought into the project in January 2011 when Assange was living with a group of supporters at Ellingham Hall in Norfolk, while on bail over allegations of rape and sexual assault in Sweden.

The "studenty WikiLeaks charabanc" was at times bold and highly effective, writes O'Hagan – during the Egyptian uprising, when president Mubarak tried to close the country's phone network which was routed through Canada, he describes Assange and other staffers hacking into the Canadian telecom firm from their Norfolk kitchen table to reverse the Mubarak shutdown, then leaning back to eat chocolates as the revolution continued.

Former Cuban president Fidel Castro, the ghostwriter was told, had sent a message to say WikiLeaks was the only website he liked.

But the Australian's suspicion of the authorities led to a broader paranoia, writes O'Hagan, describing one car journey in which Assange demanded the writer pull off a small country road to avoid a white Mondeo that he was convinced was tailing them, but which turned out to be a taxi dropping a child off from school.

A trip to the local police station, which Assange was obliged to visit daily as a condition of his bail, was completed only after Sarah Harrison, described by O'Hagan as Assange's PA and girlfriend, had checked the bushes for assassins.

It was, by O'Hagan's account, an occasionally surreal life: one of those who flew to Ellingham Hall by helicopter to pay court was the billionaire Matthew Mellon, who later sent a delivery of Savile Row suits by designer Oswald Boateng which Assange then wore constantly.

When a group of company presidents offered a fee of £20,000 for an hour's Skype time with Assange, he told Harrison: "If Tony Blair – a war criminal – can get £120,000, I should get at least £1 more than him."

The WikiLeaks founder was highly vocal on the subject of former collaborators whom he now regarded as "enemies" – a long list to which his publishers would ultimately be added, writes O'Hagan, but among which the Guardian and New York Times were judged as particular offenders.

Assange regarded this newspaper as having "double-crossed" him, writes O'Hagan. "It was an early sign of the way he viewed 'collaboration': the Guardian was an enemy because he'd 'given' them something and they hadn't toed the line, whereas the Daily Mail was almost respected for finding him entirely abominable."

He describes the Australian as being "a little put out by the global superstardom" of Edward Snowden following his leaks to Glenn Greenwald and the Guardian. While Snowden was marooned in Moscow airport, writes O'Hagan, "Julian was keen to help him and keen to be seen to be helping him"; shortly afterwards Assange sent Harrison to Moscow where she acted for a time as the American's "legal advisor".

When he asked Assange "just how good" was Snowden, O'Hagan writes, he was told: "He's number nine." "In the world? Among computer hackers? And where are you?" "I'm number three."

The relationship between O'Hagan and Assange remained amicable throughout their collaboration – even as the book deal collapsed, Assange described it as a "close friendship" – and the two have remained on good terms until recently. (The Australian, he concedes, will "hate this" – meaning his lecture – but in signing on with a ghostwriter, Assange "forgot what a writer is, someone with a tendency to write things down and seek the truth".)

However, O'Hagan says Assange's contradictions "could rock you off your feet": during the making of The Fifth Estate, the recent Assange biopic (based in part on a book by Guardian journalists) which he angrily denounced, O'Hagan describes being called by Assange one day to suggest that the writer offer himself as a consultant to the movie and split his fee with him.

But while the ghostwriter writes of feeling "a kind of loyalty to Julian's vulnerability, especially (not in spite of) his role as enemy to himself", the "clarifying" moment in their relationship came in May 2011 when Assange had tried persuade O'Hagan to join him in flying to the Hay festival in a Daily Telegraph helicopter, to promote a book that by that time "we both knew he would never produce".

"He wanted me to see him on the helicopter and he wanted me to assist him in living out that version of himself he so craves. He was flying in from Neverland with his own personal JM Barrie ... What could be nicer for the lost boy of Queensland with his silver hair and his sense that the world of adults is no real place for him?"

Pondering on the enigma that is Assange, O'Hagan concludes that it is difficult to determine whether the WikiLeaks founder is another Daniel Ellsberg, the Pentagon Papers leaker, or John Wilkes, the 18th-century radical politician, or the fictional character Charles Foster Kane, who was "abusive and monstrous in his pursuit of the truth that interests him, and a man who, it turns out, was motivated all the while not by high principles but by a deep sentimental wound. Perhaps we won't know until the final frames of the movie."