In his decision, Justice Miller set aside the ministers' consent and directed them to reconsider the application.
Former CraFarms owner Allan Crafar welcomed the decision.
"It's exciting for us," he told Campbell Live last night.
"Without money you can't do much, but the Fay consortium has done a great job, for us in a lot of ways. In the meantime, we've been flat out organising money and we're in a position to match whatever the Chinese might have offered."
Mr Crafar lost the 16 farms after running up a $194 million debt.
However assured Campbell Live host John Campbell he now had the money to purchase the farms back, somewhere in the ballpark of $200 million.
He said he would now "immediately" approach the receiver to buy his farms back.
"It's been a pretty hard road watching for nearly two-and-a-half years while people squabble over your carcass, basically, and run your farms not how you would run them."
Mr Crafar said if he were not able to purchase the land back he did not favour one rival bid over the other - although believed the farm land should be controlled by New Zealanders.
In his decision, Justice Miller said the relevant legislation was intended to allow overseas investment in farmland only where it was likely to benefit New Zealand.
However, the economic benefits of Shanghai Pengxin's investment were materially overstated in the OIO recommendation.
Read the decision here.
Prime Minister John Key said Justice Miller had used a different interpretation of the Overseas Investment Act than used in earlier decisions.
While both the OIO and the two ministers compared the Crafar farms in their distressed state to the benefits that would come from a sale to Shanghai Pengxin, Justice Miller said the benefits should be compared to what would happen if the same land was bought by an alternative buyer.
OIO manager Annelies McClure said the office would apply the approach directed by the court in its new recommendation to the ministers, which it expected to make "in a matter of days".
Justice Miller's judgment might be relevant to other current and future applications but would not affect consents already granted, she said.
Mr Key denied that Justice Miller's decision was an embarrassment for his Government.
"The question is whether the Overseas Investment Office correctly interpreted the benefits test in one of those two sections, so it's not a matter for the Government."
He was waiting on opinions about the decision from Crown Law and the OIO but was unlikely to appeal it.
However, the Government does have the option of amending the Overseas Investment Act to clarify how the economic benefits of foreign investment should be assessed.
Labour Party leader David Shearer said he believed Mr Key and his Government had always wanted the farms sold to Shanghai Pengxin.
"The decision by the court vindicates the fact that we believe it's wrong and the rest of New Zealand believes it was wrong."
Mr Shearer said he hoped that when considering the OIO's new recommendation, Mr Williamson and Dr Coleman "realise that there's no value added for New Zealand in going forward as it is and that the ministers really do their jobs".
Shanghai Pengxin spokesman Cedric Allan said the company was "astonished" by the decision.
"As far as we can tell there's never been a requirement in any application to the Overseas Investment Office to contrast the benefits which the applicant is bringing to the country with the theoretical benefits which might be obtained by some New Zealand-based person buying the same assets."
Mr Allan said Shanghai Pengxin did not intend mounting a legal challenge to Justice Miller's decision but remained committed to its offer. The Crafar farms receivers, Korda Mentha, had agreed to allow time for the OIO and ministers to reconsider it.
A spokesman for Sir Michael's consortium, Alan McDonald, said the decision was welcome and confirmed the consortium's view that Shanghai Pengxin's offer brought no real economic benefit to NZ and was not in the best interests of New Zealanders.
"It is reassuring that a High Court judge has come to a similar conclusion."