OTTAWA, Aug 2 (Reuters) - Canadian Prime Minister Justin Trudeau and his wife Sophie said on Wednesday they were separating in an unexpected announcement that appeared to mark the end of the couple's 18-year high-profile marriage.

The couple had talked frankly in the past about difficulties in their relationship and in recent years were seen less often together in public.

Trudeau, 51, and Sophie Gregoire Trudeau, 48, were married in May 2005 and have three children, aged 15, 14 and nine. On their anniversary in 2020, he described her as "my rock, my partner, and my best friend."

For Trudeau, there are also painful historical parallels. His father, former Prime Minister Pierre Trudeau, separated from his wife, Margaret, in 1977, when he was in office.

The development is one of the biggest personal crises for Trudeau since he became prime minister in 2015, especially since he often stresses the importance of family life.

The couple made the announcement a week after Trudeau unveiled a massive cabinet shuffle in a bid to boost the fortunes of his Liberal Party, which is trailing in the polls. Aides said he was determined to lead the Liberals into the next election, which must be held by October 2025.

"Sophie and I would like to share the fact that after many meaningful and difficult conversations, we have made the decision to separate," Trudeau said on Instagram. Gregoire Trudeau posted an almost identical message on her own Instagram account.

The Canadian Broadcasting Corp said Public Safety Minister Dominic LeBlanc, one of Trudeau's closest allies, would brief members of the cabinet later on Wednesday.

The CBC also said Trudeau was likely to speak publicly about the separation this week.

Trudeau's office said the two had signed a legal agreement, stressing that the couple would focus on raising their children. The family will go on vacation together next week.

Gregoire Trudeau will be moving into separate accommodation in Ottawa but plans to spend plenty of time with the children in Rideau Cottage, the prime minister's official residence, to ensure they have as normal an upbringing as possible, said a source familiar with the situation.

The source, who requested anonymity because of the extreme sensitivity of the situation, said the couple would have joint custody of the children.