SHANGHAI — Some major Japanese brands announced factory shutdowns in China on Monday and urged their Japanese workers in the country to stay indoors ahead of what could be more angry protests over a territorial dispute between the two biggest economies in Asia.

China’s worst outbreak of anti-Japan sentiment in decades led to demonstrations over the weekend and violent attacks on well-known Japanese companies, like the carmakers Toyota and Honda, forcing frightened Japanese into hiding and prompting the Chinese state news media to warn that trade relations could be in jeopardy.

Hong Lei, a Chinese Foreign Ministry spokesman, said the government would protect Japanese companies and citizens and called for protesters to obey the law.

China and Japan, which generated two-way trade of $345 billion last year, are arguing over the uninhabited islets in the East China Sea, a longstanding dispute that erupted last week when the Japanese government decided to buy some of them from a private Japanese owner.