TikTok has avoided a government-ordered block on new downloads in the US after a judge issued a temporary injunction.
The video-sharing app had faced being removed from Apple's App Store and Android's Google Play marketplace at midnight local time in Washington DC.
Existing US-based users would have been able to have continued using it.
But they would not have been able to have re-downloaded the app if they had deleted it from their phones, nor have been offered software updates.
Judge Carl Nichols of the US District Court for the District of Columbia issued the injunction on Sunday evening having held a 90-minute hearing earlier in the day.
He wrote that the government had "provided ample evidence that China presents a significant national security threat", but added that specific evidence that TikTok itself posed a risk and that taking its app off stores was the required was "less substantial".
TikTok welcomed the intervention, and vowed to keep defending its rights.
"We're pleased that the court agreed with our legal arguments and issued an injunction preventing the implementation of the TikTok app ban," it said in a statement.
TikTok had argued that forcing it off the iOS and Android app stores would have violated the First and Fifth Amendments of the US constitution.
It claimed that preventing some users joining the app unlawfully impinged upon their freedom of speech and that the firm's own right to due process would have been breached by not giving it a proper opportunity to defend itself first.
"How does it make sense to impose this app store ban tonight when there are negotiations underway that might make it unnecessary?" added a member of the app's legal team.
The US government's lawyers in turn had described the app's parent as being "a mouthpiece" for the Chinese Communist Party (CCP).
The ruling comes one week after another Chinese app - WeChat - that also faced a ban, was given its own last minute reprieve by the US courts.
The long-term fate of TikTok in the US is still unclear. At present it is owned by a Chinese company, Bytedance, but operated as a separate entity to Douyin - a parallel version used by Chinese consumers.
The Trump administration has claimed Bytedance's involvement poses a unacceptable national security threat, because it would have to comply with an order to support the CCP's "malicious collection of American citizens' personal data".
Bytedance denies this, saying that TikTok's user data is kept in the US and Singapore, and so is not subject to Chinese law.
Even so, after being threatened with a ban, a week ago TikTok said that it had agreed a deal to let database company Oracle and retail giant Walmart take up to a 20% stake in a new spun-off entity called TikTok Global ahead of shares in the endeavour being floated.
But President Trump subsequently said he would not accept any arrangement that did not involve Bytedance ceding control to the two US firms.
TikTok's statement on Monday suggested negotiations over the deal were still ongoing.
"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," it said.
To further complicate matters, Beijing has yet to announce whether it will grant Bytedance a licence to include TikTok's algorithms in any deal.
Algorithms power the app's recommendation engine, deciding which videos to show to each user, based on the ways they have previously interacted with the product.
The algorithms are highly responsive to each person's interests, quickly picking up on shifts in behaviour, and are credited with helping make the app so popular.
If China refused to let them be included in a deal, it could scupper any sell-off.
A 'stay of execution' for a social media phenomenon
TikTok really has morphed into a platform that rivals Instagram and Facebook in America.
For the US to ban the app would be simply unprecedented. And for now, it's been given a stay of execution.
The court will now take its time, as it looks into whether it's a threat to national security.
One thing that was striking in the open evidence presented though was that there was no smoking gun.
There were lots of assertions, for example that TikTok's owner Bytedance was a "mouthpiece" for the Chinese government, but no killer punch.
What this delay does is buy TikTok much needed time. They need to do three things.
Wrap up a deal with Oracle and Walmart, get Trump to support it and then get the Chinese government to approve it.
And all whilst the clock runs down. This TikTok saga isn't even close to being done.
TikTok has said it has more than 100 million active users in the US and about 700 million worldwide.
It has claimed even a temporary ban would threaten its business.
"[A] ban will cause our user base to stagnate and then precipitously decline," wrote interim boss Vanessa Pappas in a court filing.
"For TikTok to remain competitive, continued growth at this stage in our development is critical."
The US government has issued two executive orders targeting TikTok. While the first is designed to prevent it being distributed via Apple and Google, the second is more far-reaching.
Due to come into force on 12 November, it is designed to shut the app down outright in the US, if the president's national security concerns are not resolved.
March 2012: Bytedance is established in China and launches Neihan Duanzi - an app to help Chinese users share memes
September 2016: Bytedance launches the short-form video app Douyin in China
August 2017: An international version of Douyin is launched under the brand TikTok in some parts of the world, but not the US at this time
November 2017: Bytedance buys lip-synch music app Musical.ly
May 2018: TikTok declared world's most downloaded non-game iOS app over first three months of the year, by market research firm Sensor Tower
August 2018: Bytedance announces it is shutting down Musical.ly and is moving users over to TikTok
February 2019: TikTok fined in US over Musical.ly's handling of under-13s' data
October 2019: Facebook's Mark Zuckerberg publicly criticises TikTok, accusing it of censoring protests
November 2019: The Committee on Foreign Investment in the United States opens a national security investigation into TikTok
May 2020: TikTok hires Disney executive Kevin Meyer to become the division's chief executive and chief operating officer of Bytedance
June 2020: India bans TikTok among dozens of other Chinese apps
July 2020: US Secretary of State Mike Pompeo, and then President Trump, say TikTok might be banned
August 2020: Microsoft and Oracle make rival approaches to acquire or otherwise operate TikTok in the US and three other markets. Mr Meyer announces he is leaving the company because the "political environment has sharply changed"
September 2020: TikTok rejects Microsoft's bid, paving way for Oracle and Walmart to clinch a deal. The US Department of Commerce gives a one-week extension to its original app-store-ban deadline, and a judge then stops the ban from coming into effect. TikTok says it still aims to turn the proposed change of ownership into a formal agreement