A U.S. government order banning TikTok from app stores imposed by the Trump administration — which had been set to kick in Sunday, Sept. 27, at midnight ET — was temporarily halted by a federal judge.

Judge Carl Nichols of the U.S. District Court for the District of Columbia issued the ruling Sunday night, granting TikTok’s motion for a preliminary injunction just three and a half hours before the ban was to take effect. Trump appointed Nichols to the federal bench in June 2019.

The Commerce Department originally set Sept. 20 for the TikTok download ban, citing Trump’s declaration that the Chinese-controlled app represents a threat to U.S. national security. The agency delayed the deadline to Sept. 27, given Trump’s preliminary approval a week ago of owner ByteDance’s deal to transfer TikTok ownership to American firms including Oracle and Walmart.

In a statement following the ruling, TikTok said: “We’re pleased that the court agreed with our legal arguments and issued an injunction preventing the implementation of the TikTok app ban. We will continue defending our rights for the benefit of our community and employees. At the same time, we will also maintain our ongoing dialogue with the government to turn our proposal, which the President gave his preliminary approval to last weekend, into an agreement.”

TikTok, in its motion for a preliminary injunction blocking the download ban last week, alleged that Trump was motivated “by political considerations relating to the upcoming general election” rather than by any sort of national security concerns. TikTok argued the ban violated its Fifth Amendment right to due process as well as its users’ First Amendment right to free speech. The company claimed it has “made extraordinary efforts to try to satisfy the government’s ever-shifting demands and purported national security concerns.”

U.S. government lawyers, in a response filed Friday, argued that TikTok had not proven the Sept. 27 ban would cause “irreparable harm” to its business.

“[T]he public interest tilts decidedly against Plaintiffs insofar as their requested relief would necessarily infringe on the President’s authority to block business-to-business economic transactions with a foreign entity in the midst of a declared national-security emergency,” Justice Department attorneys wrote in a statement opposing the requested injunction.

Nichols’ opinion accompanying his order granting the TikTok motion for a preliminary injunction stopping the download ban was sealed. The judge ordered the parties to review the opinion by Sept. 28 at 11 a.m. and then inform the court whether the opinion can be unsealed. In addition, Nichols ordered TikTok and U.S. government lawyers to file a joint status report by Sept. 30 proposing a schedule for further proceedings.

At a hearing Sunday morning, Nichols seemed sympathetic to TikTok’s argument that its right to due process was infringed. The judge commented that the U.S.’s action appeared to be “largely a unilateral decision with very little opportunity for plaintiffs to be heard, and the result — whether we’re talking about November or tonight — is a fairly significant deprivation.”

While Nichols granted TikTok’s motion to stop the Sept. 27 download ban, the judge rejected the company’s request to halt Trump’s executive order that would effectively shut down the app Nov. 12 if a deal to sell TikTok doesn’t materialize.

Trump gave ByteDance a Nov. 12 deadline to divest TikTok’s U.S. business. The Chinese internet giant reached a deal with Oracle and Walmart to form a new U.S.-based company, TikTok Global, that would be 12.5% owned by Oracle and 7.5% by Walmart. TikTok Global would file an IPO on a U.S. stock exchange within 12 months of the deal closing.

But the agreement is not a done deal. Amid conflicting reports from ByteDance and Oracle about who will control the new TikTok Global, the Chinese government may be leaning toward nixing it. “China has no reason to give the green light to such a deal, which is dirty and unfair and based on bullying and extortion,” China Daily, the Chinese Communist Party’s official English-language newspaper, said in an editorial last week. ByteDance has applied for an export license from the Chinese government, evidently as part of trying to get clearance for the TikTok deal.

TikTok previously sued Trump and the Commerce Department on Aug. 24, raising objections similar to those it made in the motion seeking an emergency ruling to block the download ban. In a separate case, a judge in the U.S. District Court for the Eastern District of Pennsylvania on Sunday denied a request filed by three TikTok creators to block the app’s ban, saying the trio had not proven they would suffer “immediate, irreparable harm.”

Meanwhile, the U.S. government’s total ban on Tencent’s WeChat app was set to go into effect Sept. 20, but a judge issued a temporary stay of the Commerce Department’s order in that case, citing the First Amendment. The Trump administration has asked the California federal court to drop the preliminary injunction until an appeals court has ruled in the case.