The Supreme Court seemed inclined on Friday to uphold a law that could effectively ban TikTok, the wildly popular app used by half of the country.

Even as several justices expressed concerns that the law was in tension with the First Amendment, a majority appeared satisfied that it was aimed not at TikTok’s speech rights but rather at its ownership, which the government says is controlled by China. The law requires the app’s parent company, ByteDance, to sell TikTok by Jan. 19. If it does not, the law requires the app to be shut down.The government offered two rationales for the law: combating covert disinformation from China and barring it from harvesting private information about Americans. The court was divided over the first justification. But several justices seemed troubled by the possibility that China could use data culled from the app for espionage or blackmail.

“Congress and the president were concerned,” Justice Brett Kavanaugh said, “that China was accessing information about millions of Americans, tens of millions of Americans, including teenagers, people in their 20s.”

That data, he added, could be used “over time to develop spies, to turn people, to blackmail people, people who a generation from now will be working in the FBI or the CIA or in the State Department.”

Noel J. Francisco, a lawyer for TikTok, said he did not dispute those risks. But he said the government could address them by means short of effectively ordering the app to, as he put it, “go dark.”

Chief Justice John Roberts appeared unpersuaded.

“Are we supposed to ignore the fact that the ultimate parent is, in fact, subject to doing intelligence work for the Chinese government?” Roberts asked.

The court has put the case on an exceptionally fast track, and it is likely to rule by the end of next week. Its decision will be among the most consequential of the digital age, as TikTok has become a cultural phenomenon powered by a sophisticated algorithm that provides entertainment and information touching on nearly every facet of American life.

The Supreme Court has repeatedly taken up cases on the application of free speech principles to giant technology platforms, though it has stopped short of issuing definitive rulings. It has also wrestled with the application of the First Amendment to foreign speakers, ruling that they are generally without constitutional protection, at least for speech delivered abroad.

Justice Elena Kagan acknowledged that TikTok, which is an American company, has First Amendment rights. But she asked, “How are those First Amendment rights really being implicated here?”

If ByteDance divests TikTok, Kagan said, the American company remains free to say whatever it likes.

Jeffrey L. Fisher, a lawyer for users of the app, said his clients should not be required to move to other platforms, using an analogy involving newspapers.

“It’s not enough to tell a writer, well, you can’t publish an op-ed in The Wall Street Journal because you can publish it in The New York Times instead,” he said, adding that “TikTok has a distinct editorial and publication perspective.”

The law, enacted in April with broad bipartisan support, said urgent measures were needed because ByteDance was effectively controlled by the Chinese government, which could use the app to harvest sensitive information about Americans and to spread covert disinformation.

Saying that the law violates both its First Amendment rights and those of its 170 million American users, TikTok has urged the court to strike down the law. It has repeatedly argued that a sale is impossible, in part because China would bar the export of ByteDance’s algorithm.

TikTok has also contended that there is no public proof that the U.S. government’s concerns about Chinese interference have come to pass in the United States. But the government has claimed in court filings that the app has acceded to Beijing’s demands to censor content outside China.

Several justices seemed to be searching for a narrow ground on which to uphold the law, and they leaned toward the government’s interest in protecting Americans’ data.

Elizabeth B. Prelogar, the U.S. solicitor general, defended the law on that ground, saying that China “has a voracious appetite to get its hands on as much information about Americans as possible, and that creates a potent weapon here.”

Justice Samuel Alito expressed concerns about what he said was “an enormously powerful, popular application” that is “gathering an arsenal of information about American citizens.”

The court was more divided on the question of whether potential covert disinformation or propaganda justified the ban.

Echoing a point made in the appellate court ruling upholding the law, Kavanaugh said the law had historical analogues.

“There is a long tradition of preventing foreign ownership or control of media in the United States,” he said.

ByteDance has said that more than half of the company is owned by global institutional investors and that the Chinese government does not have a direct or indirect ownership stake in TikTok or ByteDance.

The government’s brief acknowledged that ByteDance is incorporated in the Cayman Islands but said that its headquarters are in Beijing and that it is primarily operated from offices in China.

The deadline set by the law falls one day before the inauguration of President-elect Donald Trump. In an unusual brief last month, nominally in support of neither party, he asked the justices to temporarily block the law so that he could address the matter once in office.