A whistleblower who helped expose allegations of Australian war crimes in Afghanistan has pleaded guilty to leaking classified information.
David McBride was due to face trial next week, but changed his plea after a legal ruling scuppered his defence.
McBride - an ex-military lawyer - said he felt a moral duty to speak up after his internal complaints were ignored.
A landmark inquiry later found evidence that Australian forces had unlawfully killed 39 Afghans during the war.
McBride admits he gave troves of documents to the Australian Broadcasting Corporation (ABC), because he was concerned about what he then thought was the "over-investigation" of troops, the court heard.
He pleaded guilty on Friday to three charges of stealing and unlawfully sharing secret military information.
The information he provided underpinned a series of reports in 2017 called The Afghan Files, which gave unprecedented insight into the operations of Australia's elite special forces in Afghanistan, and contained allegations of war crimes.
Months after McBride's arrest in 2019, the ABC was raided by federal police, who were also building a case against the journalist, Dan Oakes, who wrote the reports. Prosecutors declined to charge Mr Oakes however, saying it was not in the public interest.
McBride - who initially faced five charges - had intended to argue his disclosure was protected by whistleblower safeguards in Australia. But his legal team say they were forced to withdraw that defence after much of their arguments were ruled to endanger national security.
After failed attempts to convince Attorney General Mark Dreyfus to intervene and drop the prosecution - as Mr Dreyfus did in the case of fellow whistleblower Bernard Collaery last year - McBride then tried to argue that he had a duty to leak the documents, because doing so was in the public interest.
After several days of pre-trial argument, a judge rejected the argument and ruled that they could not be put to a jury.
His defence lawyer Mark Davis said this would have dealt his defence a "fatal blow", with McBride eventually entering a guilty plea.
Advocates say his case showed that Australia's whistleblower protections were not strong enough.
"This is a dark day for democracy in Australia," said Rex Patrick, a former Senator and founder of the Whistleblower Justice Fund.
"There is no public interest in prosecuting whistleblowers, and certainly no public interest in sending them to jail," added Kieran Pender, from the Human Rights Law Centre, who called for McBride to be pardoned.
A spokesperson for the Attorney General said it would be inappropriate to comment while the proceedings are still before the court.
McBride will be sentenced early next year.