Thousands of mostly peaceful counter-protesters gathered in Boston to oppose white supremacy and counter a right-wing "free speech" rally, but Donald Trump referred to them as "anti-police agitators" in a tweet on Saturday.

The president was quickly hit with criticism for his response to the mostly nonviolent protests and soon followed up with praise for the protesters.

"I want to applaud the many protestors in Boston who are speaking out against bigotry and hate," Trump tweeted. "Our country will soon come together as one!"

Trump also noted that the country has been divided for decades and sometimes "you need protest in order to heal."

"Today, Boston stood for peace and love, not bigotry and hate. We should work to bring people together, not apart," Boston Mayor Marty Walsh tweeted in response to Trump.

Though Boston police said at one point that rocks and bottles filled with urine were thrown at officers, they told media at a press conference that around 40,000 people had attended the protests and remained largely peaceful. There were, however, 27 people who were arrested, mostly for disorderly conduct and some for assault or battery on police

"99.9% of the people were here for the right reason, and that was to fight bigotry and hate," Boston police commissioner William Evans said.

The protest in Boston comes one week after violence erupted at a white nationalist rally in Charlottesville, Virginia that left Heather Heyer, a counter-protester, dead.

Trump drew backlash from around the world for initially refusing to single out white nationalists and white supremacists, instead, laying blame "on many sides." He later condemned the white nationalists but continued to equate their actions with those of the counter-protesters.