Prime Minister Justin Trudeau knew his relationship with former justice minister and attorney general Jody Wilson-Raybould was problematic long before his government was crippled by her allegations against him during the SNC-Lavalin affair.

"A number of times over the first years of my government," Trudeau mused weeks after the dust kicked up by the controversy began to settle, "I grumbled to myself that it was difficult for me to not have a minister of justice that I was super-sympatico with."

"But it wasn't the kind of relationship that I would have ideally imagined, I don't think [it's what] she would have ideally imagined," he said, of Wilson-Raybould, who only a few years earlier had been a highly touted candidate and a historic member of his cabinet.

Trudeau's reflections on his most damaging controversy to date are contained in a new book, Promise and Peril: Justin Trudeau in Power, by CBC News senior writer Aaron Wherry that is being published by HarperCollins Canada on Aug. 20.

Of all the news stories that caused the prime minister headaches over the course of his term, none came close to the SNC-Lavalin affair in terms of the damage done to his government in public opinion polling. In the process, it demonstrated how hard it is for a government to manage a political crisis emerging from within its own circles.

In the book, Wherry describes for the first time some of the key conversations that happened inside Trudeau's government at the height of the controversy, and how Trudeau and his staff struggled to navigate their way out.

Trudeau played a key role in recruiting Wilson-Raybould as a candidate in the 2015 election. Naming her to cabinet as Canada's first Indigenous justice minister was meant to send a powerful message about his government's commitment to reconciliation with Indigenous Canadians.

But even before the SNC controversy erupted, Trudeau seemed to understand the inherent risks in naming her to the portfolio. "I totally understand that when you have powerful, positive symbols it's also possible to have that snap back on you when you make other decisions," he told Wherry in one of the many exclusive interviews that went into the book.

"We didn't appoint Jody to be a symbol — we appointed her to be a great minister of justice and attorney general."

Trudeau, Wilson-Raybould and Gov.-Gen. Julie Payette attend a swearing-in ceremony in which Wilson-Raybould was installed in the Veterans Affairs portofolio. (Sean Kilpatrick/The Canadian Press)

But ultimately Wilson-Raybould didn't stay in the job. When Treasury Board President Scott Brison decided to leave cabinet, Wilson-Raybould was shuffled out of Justice and moved to the veterans affairs file. It was suggested by a reporter at the swearing-in ceremony that she had been demoted, something the prime minister said was simply untrue and that her new job constituted a "deep and awesome responsibility."

It wasn't until a Globe and Mail story almost a month later that new questions would be raised about that shuffle.

The paper published a story suggesting senior government representatives had inappropriately pressured Wilson-Raybould to approve a deferred prosecution agreement for SNC-Lavalin — an arrangement that would have allowed the Quebec-based engineering firm to avoid prosecution on corruption and fraud charges. Trudeau initially denied it had happened. Wilson-Raybould, he later learned, was not pleased.

Wherry writes that Trudeau subsequently met privately with Wilson-Raybould at the Vancouver airport in the first of three meetings over two days.

'Why are you telling me this now?'

Trudeau told Wherry that Wilson-Raybould told him his staffers were not serving him well and brought up the allegation of undue pressure to cut SNC-Lavalin a deal.

"My first question was, 'Why now? Why are you telling me this now and not months ago?'" Trudeau told Wherry.

Trudeau and Wilson-Raybould met the next morning, shortly before Trudeau made an infrastructure announcement. Trudeau told Wherry he used the occasion to reassure his minister. At a press conference soon after that meeting, Trudeau was asked about the allegation; again he said he had told Wilson-Raybould she was free to make her own decisions on the SNC-Lavalin file and suggested that "her presence in cabinet should speak for itself."

Soon afterward, Wilson-Raybould asked for a third meeting with the prime minister — during which she told him she was resigning from cabinet.

Watch Trudeau discuss his meetings with Wilson-Raybould:

PM Justin Trudeau says he and former Justice Minister Jody Wilson-Raybould have talked a couple of times since he arrived in B.C. yesterday, and confirmed that they spoke previously about matters involving the Director of Public Prosecutions being hers alone. 2:33

As Wherry tells it, "Trudeau himself seems not to fully understand her reasoning. 'The next morning I said that I was surprised and disappointed, and I was.'"

Wherry took Trudeau's version of events to Wilson-Raybould for her reaction. She wouldn't comment, saying the matter was subject to cabinet confidentiality — but she told Wherry that he was "receiving, as a result, false, self-serving/one-sided and inaccurate accounts of relevant events. This is not fair."

The former minister would not confirm or deny details of the conversations as reported.

By the time the dust settled on the SNC-Lavalin affair, Trudeau's principal secretary and close friend Gerry Butts had resigned in the face of Wilson-Raybould's claim that she was pressured by the highest levels of the Trudeau government to give the company a deferred prosecution agreement. Wherry's book reveals that Butts actually had tried to resign several times beforehand, but Trudeau turned him down.

"I was very confident that he had not done anything wrong," Trudeau told Wherry.

'I really regret it'

Trudeau made efforts to keep Wilson-Raybould and her caucus ally Jane Philpott in the Liberal fold after both ministers resigned in protest from cabinet. While news reports at the time said those reconciliation attempts continued until just 24 hours before Wilson-Raybould and Philpott were ejected from caucus, Wherry reveals they got close enough to success for all parties to begin crafting a joint statement.

But Trudeau would not admit to any ethical lapse, and suggested that his refusal caused the reconciliation attempts to founder.

"I can't apologize for something that I don't fundamentally think we did wrong," he told Wherry. "And that was really sort of the key of it. I'd say there's lots of things that we needed to learn from, and I really regret it."

Watch Trudeau announce the removal of two ministers from the Liberal caucus:

Prime Minister Justin Trudeau told Jody Wilson-Raybould and Jane Philpott they can no longer sit as Liberal MPs 0:33

There was to be no agreement, no return to normal. Trudeau ejected Wilson-Raybould and Philpott from the caucus, saying their attacks had undermined the bonds of trust between Liberals and aided their political rivals.

Wilson-Raybould and Philpott are running as Independent candidates in the Oct. 21 election. Trudeau and his party took a massive hit in the polls from which they have not fully recovered.