Tensions between China and Vietnam over a territorial dispute have escalated as riots erupted in Vietnam.

In a rare outpouring of public nationalist anger, 20,000 Vietnamese rampaged in two industrial zones in the country, attacking what they thought were Chinese factories and setting them ablaze.

It is rare for Vietnam's authorities to allow anti-Chinese anger to explode in public and some analysts take that as a worrying sign that the tensions could escalate.

An unlikely early casualty in the dispute were Taiwanese businesses in Vietnam. Some of the factories torched by the mobs were Taiwanese and had no connection with mainland China, with whom the Vietnamese are actually in dispute.

It was a case of mistaken identity but the damage was real and costly. An industry association said that Taiwan companies with business in Vietnam had already lost billions of dollars since the dispute between China and Vietnam ignited earlier this month.

Among the Taiwanese companies whose factories were burned down were Formosa Plastics Group, said Serena Liu, chairwoman of the Council of Taiwanese Chamber of Commerce in Vietnam.

Liu said workers were "terrified and scared" at the Binh Duong industrial park, adding that those who tried to flee were halted by roadblocks.

Some foreign firms responded immediately to the clashes by freezing operations in Vietnam.

A number of companies halted operations with immediate effect. Global exporter Li & Fung said a number of its suppliers in Vietnam had stopped production, while Yue Yuen Industrial Holdings, which makes footwear for Adidas and Nike, said its operations in Vietnam were being suspended as a precaution.

Moreover, the spat could scupper extensive economic ties between Hanoi and Beijing.

According to figures from the Vietnamese statistics office, China was Vietnam's biggest source of imports in 2013, spending $36.8bn in a 26.7% increase from 2012. Vietnam exported $13.1bn worth of goods and services to China in the same period, up 2.1% from the year before.

Chinese investment in Vietnam reached more than $2.3bn in 2013, a sharp rise from the £371m recorded in 2012. By the end of 2013, China had 977 viable projects in Vietnam and accounted for almost 7% of total foreign investment in Vietnam, according to figures from Vietnam's planning ministry.

The relationship has been growing ever closer and these latest clashes appear to have taken many Asia-watchers by surprise. China's bellicose rhetoric over the South China Sea is not new, but the region's economies are more integrated than ever which will make any conflict more costly for the region as a whole.

While the US described China's actions as provocative and China urged the US to act with objectivity and caution, Hanoi has remained unapologetic. Emboldened by its alliance with the United States, it seems that these protests could mark the start of an unstable period for the region.