BEIJING — Over the past five months, as Beijing and Washington have exchanged fire on trade and technology, two Canadian men have been held in near-isolation in Chinese detention facilities.

On Thursday, 158 days into their ordeal, they were formally arrested, a legal step that confirms that China intends to move forward with cases against them — and that hints at the political factors at play.

Former diplomat Michael Kovrig was arrested on charges of “gathering state secrets and intelligence for overseas forces” and entrepreneur Michael Spavor on charges of “stealing and providing state secrets to overseas forces,” the Chinese Foreign Ministry said. Spokesman Lu Kang said the men were arrested “recently” but would not specify when.

The news broke as the world’s two economic superpowers clashed on the issues that frame the case: technology and trade.

Kovrig and Spavor were arrested days after Meng Wangzhou, chief financial officer for China’s Huawei Technologies, was arrested in Vancouver, B.C., on U.S. charges — and they remain caught in a broader battle between China and the United States.

Last week, trade talks between the United States and China appeared to collapse, leading both countries to levy additional tariffs on each other. On Wednesday, the U.S. government all but banned American companies from doing business with Huawei.

Against this backdrop, the formal arrest will almost certainly be interpreted as a political signal, said Julian Ku, a professor of law at Hofstra University. “The message is: ‘We are still mad about Meng and Huawei, and we are going to continue with our charges. We are not backing away from this,’ ” he said.

In the short term, tough talk from Beijing and Washington will do little to help Canada, which has been caught in the middle of the U.S.-China showdown for months. 

Spavor, a businessman based near the China-North Korea border, and Kovrig, who conducts geopolitics research, were first detained by Chinese state security on Dec. 10, a week after Canadian airport authorities arrested Meng at the behest of U.S. law enforcement.

The Huawei executive has since been undergoing extradition proceedings in a Canadian court, which is deciding whether to send her to the United States to face bank-fraud charges tied to alleged violations of sanctions against Iran. 

A Canadian judge this month allowed Meng to move from a $4.2 million mansion into a bigger, $10 million mansion for security reasons. Meng, the daughter of Huawei’s founder, owns several homes in Canada.

Meng’s attorneys have argued that her constitutional rights were violated when she was interrogated for three hours at Vancouver’s airport and that she should be released.

China casts her case as an effort to constrain the country. It has repeatedly issued implicit warnings that Canada will pay a steep price if Meng is handed over. Chinese officials also stopped some shipments of canola, a critical Canadian export, raising worries of economic retaliation to come.

Weeks after Meng’s arrest, China revisited a 15-year prison term for Canadian Robert L. Schellenberg in a drug-trafficking case and sentenced him to death.

Last week, a Chinese court scheduled Schellenberg’s appeal hearing to begin hours after Meng faced an extradition hearing in Vancouver. After a Canadian court pushed back a decision in Meng’s case, the Chinese court announced it would delay a ruling on whether Schellenberg would be put to death.

It is not clear what the latest legal step means for Kovrig’s and Spavor’s future. 

Canadian officials have stressed from the start that Meng’s arrest was a legal decision, not a political one, but a tweet from President Trump undermined their claim.

In December, Trump tweeted that he would intervene in the Meng case to get a better trade deal with China. Though U.S. officials have since backed away from the offer, the notion that Meng’s case is politically motivated has lingered.

With the Meng case and the Kovrig and Spavor cases heading toward what could be lengthy legal proceedings, a deal looks less likely, at least for now. 

“I think formal arrests suggest China has made up its mind that it wants to get tough with Canada over at least the medium term,” said Lynette Ong, an associate professor of political science at the University of Toronto.

But, she added, “it is still possible to negotiate for their release.”

The formal start of proceedings against Kovrig and Spavor could lead to changes in conditions on the ground, though there are no guarantees. 

Since December, both men have been kept in cells at undisclosed locations with lights on round-the-clock and without access to lawyers or family members, people familiar with the matter say.

The two have been allowed short consular visits once a month, during which they are not permitted to discuss the cases against them with Canadian diplomats.

Ku said conditions could improve, at least marginally. “It’s not great to be in the official legal system, but it’s much worse to be where they were before,” he said.

Rauhala reported from Washington.