It was unlawful when Carwyn Jones took decisions on an investigation into his sacking of a minister accused of sexual misconduct, the High Court has ruled.
Carl Sargeant was found dead at his home days after the then-first minister dismissed him in November 2017.
The late AM's family challenged the legality of the inquiry process.
Mr Jones said the steps he took were to protect those who made complaints, but ex-minister Alun Davies warned AMs may need to take over the investigation.
Mr Davies, who was local government secretary under Mr Jones, said such action would be needed if issues raised by the High Court judgement were not resolved quickly.
The Welsh Government said it would "consider the next steps" in light of the judgement.
After the 49-year-old's death, his family said he was deprived of "natural justice" and was not informed of any of the detail of the allegations against him, despite requests and warnings regarding his mental welfare.
Following pressure from the family and Labour politicians, Mr Jones called the investigation to examine his handling of the sacking of Mr Sargeant, who was AM for Alyn and Deeside.
But Mr Sargeant's widow Bernie challenged decisions taken by Mr Jones concerning the procedures to be followed by an independent investigator looking into the former first minister's actions.
On Wednesday, two judges sitting in London ruled in her favour.
Allowing her challenge, they ruled "the procedural decisions that were taken will need to be reconsidered".
The judges concluded Mr Jones had "acted contrary" to representations made in a press statement on 10 November 2017 "that the arrangements for the investigation would be made separately from his office".
Lord Justice Haddon-Cave and Mr Justice Swift said: "In the circumstances of this case, those representations were legally enforceable and it was not reasonable for Mr Jones to depart from them."
At a hearing in Cardiff in January, Cathryn McGahey QC, for Mr Jones, said the former first minister's actions were entirely lawful and he was responsible for setting the parameters of the investigation by law.
Neil Hudgell of Hudgell Solicitors, who represents Mrs Sargeant, said: "The Sargeant family were completely unaware of the actions of the first minister, despite his assurances of independence.
"It is hugely regrettable that they have had to take matters before the High Court to shine a light on what have proven to be empty words from the former first minister."
In the assembly, Alun Davies urged Welsh ministers to respond swiftly to the High Court ruling and resolve matters or give AMs that responsibility.
"It's taken far far too long to reach a resolution on this matter, and it is something where I now believe that we need to ensure that the family have the knowledge that they seek, and that they are given the closure that they require," he said.
"Given the judgement today it is time now for the government either to take responsibility for resolving this and do so very very urgently, or it is time for this place to do that for the government," he said.
Mr Davies said it was "probably now time" to published a report on a separate inquiry which found no "unauthorised" leaking of information on Mr Sargeant's sacking before his dismissal to enable people to understand the background".
The comments were made during a question raised by former Welsh Conservative leader Andrew RT Davies.
"This is a damning judgement and the family deserve far better from us as an institution and you as a government," he said.
Plaid Cymru leader Adam Price said ministers "must commit to embracing a new a commitment to transparency" and "can begin by finally publishing the leak enquiry".
"If they refuse to do so we'll use all means at our disposal to compel them to do so."
In his response to the judgement, Carwyn Jones said: "While I'm disappointed at the decision of the court on the process, I note they didn't say anything about the decision being wrong.
"Whatever steps I took, I took them to protect the complainants.
"And given the campaign of vitriol and abuse a number of women have been subjected to as a result of these events, I make absolutely no apology for that."
The Welsh Government thanked the court for "providing clarity on what has been a complex process".
A spokesman for the team established to investigate the handling of Mr Sargeant's sacking said: "The claim did not challenge the actions of the investigator [Paul Bowen QC] whose independence and ability to continue to conduct an independent investigation are emphasised in the court's judgment.
"The investigator and his team stand ready to resume their work and look forward to receiving proposals from the Welsh Government for taking forward the investigation."
The inquest into Mr Sargeant's death is expected to reopen in July.