There had been escalating tensions between the troops and the residents of Boston pretty much since they'd landed, with the troops enforcing orders of the much-loathed colonial government that many people saw as illegal, and groups of townsfolk had been in the habit of shouting insults and provoking fights with the soldiers. According to their commander, the soldiers believed on the night that the mob had been deliberately assembled to attack them, and in the immediate aftermath of the shooting he was warned that the mob of several thousand people were now massing, intending to lynch the redcoats[1].
The acting Governor, Thomas Hutchinson, was only able to prevent further violence by going out and speaking to the mob, promising to immediately begin an investigation into the incident, and swearing on his own life that the soliders would be brought to trial. He then stayed up half the night interviewing witnesses and getting scouting reports brought to him from across the city to make sure no more mobs were assembling.
The next day, the soldiers involved in the massacre were arrested, and a delegation of radical leaders met with Hutchinson and told him that if he didn't order the all of the troops out of the city a force of up to 10,000 men would be assembled to forcibly expel them, and any blood shed would be on his hands. Hutchinson didn't want to order this, believing that ordering the removal of the troops woud be treason and was likely to fatally undermine the authority of the colonial government, but the Col. in charge of the regiments offerred to move them to a fort on one of the harbor islands (technically still in city limits, but completely remote from the populace), and Hutchinson eventually agreed to this. The troops marched out five days after the massacre.[2]
[1] Deposition of Capt. Thomas Preston, Boston Massacre Trial Documents archive.
[2]Bailey, Bernard. The Ordeal of Thomas Hutchinson, pp. 155-160