Portsmouth will become the biggest community-owned club in the country after the Pompey Trust saved the League One club from administration.
The High Court approved an agreement reached between the club's former owners Portpin over the sale of the club's Fratton Park Park ground, and the Pompey Trust will complete a £3m takeover.
The deal had been opposed by Balram Chainrai, who is still seeking to recoup the loans he gave to the club over the course of a disastrous spate of owners who nearly drove the club into non-existence.
A seminal moment for a club that has endured a miserable time since relegation from the Premier League in 2010, a round of applause greeted the announcement in court, as well as a lone shout of "Play up Pompey."
Portsmouth were placed into administration in February 2012.
Trust chairman Ashley Brown said: "This is a historic day for Portsmouth Football Club and for Pompey fans everywhere.
"At last, the tough work done over the last year is over and we can start to rebuild our club.
"Pompey fans are now days away from owning and running our club and becoming the biggest community owned football club in the country.
"We have a lot of people to thank, and much more to say, but will do that once the details of today's settlement are finalised.
"For now, we would like to offer heartfelt thanks to Pompey fans all over the world who have pledged money and have saved our club from liquidation.
"Now the next chapter of hard work begins to transform our club into something the community of Portsmouth can be proud of, both on and off the field."
Mr Justice Peter Smith, who said he was a Hull fan, had told the court the agreement would enable the trust to take control.
"I'm very pleased that the parties have agreed provisions which will preserve the club," he said. "On we go with the last three games."