Former Labor minister Ian Macdonald maintains he’s “absolutely” innocent after a New South Wales appeal court quashed his conviction for misconduct in public office and he walked from jail ahead of a retrial.

The former ALP politician had been in custody since 2017, when he was jailed for 10 years - with a minimum term of seven years - after being found guilty of two counts of wilful misconduct in public office.

But five Court of Criminal Appeal judges on Monday quashed the 69-year-old’s conviction and ordered a new trial.

They did the same for former union boss John Maitland – who was jailed for six years with four years non-parole – on two charges of being an accessory to the alleged misconduct.

“Today is about being grateful to my family and friends who have stuck by me through this long period,” Macdonald told reporters outside Long Bay jail.

He called for an immediate inquiry into several matters investigated by the state’s anti-corruption watchdog Icac before he was prosecuted.

“There was much in the way of exculpatory evidence that was hidden from the original inquiry which has set the scene, I believe, for a long period of victimisation that I have experienced in the media,” Macdonald said.

When asked if he maintained his innocence, the ex-minister replied “absolutely”.

Macdonald was alleged to have favoured the interest of Doyles Creek Mining, chaired by Maitland, over the interests of the state when he granted a Hunter Valley coal exploration licence in 2008 without a competitive tender.

However, the appeal judges on Monday found the jury was misdirected at trial on the state-of-mind element of the offence.

Jurors should have been directed that Macdonald could only be found guilty if he wouldn’t have granted consent to apply for the licence, and granted the licence itself, except for the illegitimate purpose to benefit Maitland and DCM, the appeal court held.

His lawyer, Phillip Boulton SC, wasted no time applying for bail in the NSW supreme court and it was granted by Justice Natalie Adams.

Under his bail, Macdonald will have to reside in the Blue Mountains, report to police weekly, not approach any international departure points or contact prosecution witnesses except through his lawyer.

Maitland, 72, who was also granted bail, will reside in Sydney’s eastern suburbs but otherwise faces similar conditions.

After the appeal judgment, premier Gladys Berejiklian told reporters she hadn’t kept up with the news “but I’ll look at that to see if there’s any further action the state will take”.

Their matters will next be in court on Friday.

In sentencing Macdonald, Justice Christine Adamson had described his conduct as “devious” and “extremely serious”.

“By granting consent to Doyles Creek Mining ... Macdonald was guilty of gross breaches of the trust that parliament placed in him.”

Macdonald was the second former minister of the previous state Labor government to be jailed, with former resources minister Eddie Obeid sentenced to five years imprisonment in 2016 for misconduct in office.

The decision comes less than four weeks from the NSW election on 23 March.