Blue Origin, owned by Jeff Bezos, lost its suit against the US government over a Moon exploration contract.

A US federal judge on Thursday ruled against Blue Origin brought by Jeff Bezos' company in a bid to overturn a NASA contract awarded to rival SpaceX, founded by Elon Musk, to build the next craft for Moon landings.

The ruling put an end to a months-long legal battle that had prevented the US space agency from working with SpaceX on the lunar lander called Starship, which will allow Americans to return to the Moon as part of the Artemis program.

"NASA will resume work with SpaceX under the Option A contract as soon as possible," the agency said in a statement after the ruling.

In April, NASA announced it had awarded the contract to Musk's company—a deal worth $2.9 billion.

But Blue Origin filed a complaint about the decision to the Government Accountability Office (GAO), saying the had been unfair and that NASA should have offered more than one contract.

The GAO rejected the company's claims, and Blue Origin took the matter to the Court of Federal Claims.

Judge Richard Hertling ruled in NASA's favor on Thursday. The justification for the ruling was not immediately made public, and remained under seal.

Blue Origin said in a statement that its complaint had "highlighted the important safety issues with the Human Landing System procurement process that must still be addressed."

"Blue Origin remains deeply committed to the success of the Artemis program, and we have a broad base of activity on multiple contracts with NASA to achieve the United States' goal to return to the Moon to stay," the company said.

Musk reacted in his signature style—with a bit of snark.

"YOU HAVE BEEN JUDGED!" he posted on Twitter, using a meme of the comic book and film character Judge Dredd.