HANOI, Vietnam — The Vietnamese government stopped anti-Chinese demonstrators from gathering outside the Chinese Embassy here Sunday, deploying a large number of police officers on the sidewalks around the building and urging the few pedestrians to keep walking.

In Ho Chi Minh City, the Chinese Consulate was under heavy police guard, and squads of officers in green uniforms and helmets stood by, effectively ending almost a week of anti-Chinese violence in several provinces that was inspired by the positioning of a Chinese oil rig in disputed waters of the South China Sea.

The government, embarrassed by the violence, which destroyed factories run by Taiwanese and South Korean companies, killed two Chinese workers and injured more than 100 others, said Saturday that demonstrators would be arrested and prosecuted.

In Beijing, the Foreign Ministry said Sunday that it was sending five ships to Vietnam to evacuate Chinese workers. The first ship left on Sunday from Haikou, a port on the Chinese island province of Hainan, according to the state-run Xinhua news agency. It was expected to arrive in Vietnam early Monday, the Xinhua report said.