Users of Twitter and other social media sites were warned by the Government's most senior law officer not to believe the internet was a law-free arena.
Attorney General Dominic Grieve issued the caution amid a slew of high-profile court cases involving postings made on the micro-blogging site.
A student who mocked football star Fabrice Muamba on Twitter after he collapsed with a heart attack was jailed for 56 days after admitting a racially aggravated public order offence
Another message, by a blogger who invited followers to put excrement through a local councillor's letterbox, led to a community sentence of 80 hours of unpaid work.
And 17 arrests have been made in connection with the alleged naming on Twitter of the victim in footballer Ched Evans's rape case.
Mr Grieve told BBC Radio 1's Newsbeat: "If somebody goes down to the pub with printed sheets of paper and hands it out, that's no different than if somebody goes and does a tweet.
"The idea that you have immunity because you're an anonymous tweeter is a big mistake."
He went on: "I don't want to take action but if I think it is necessary to prevent crime, such as racially aggravated harassment, then I won't hesitate to do it."
Mr Grieve decided not to prosecute footballer Joey Barton for a series of online comments about John Terry ahead of his trial, insisting they would not jeopardise the case.Suggest a correction