WASHINGTON (Reuters) - The U.S. Supreme Court on Monday moved to buttress free speech rights in the digital age, striking down a North Carolina law banning convicted sex offenders from Facebook and other social media services that play a vital role in modern life.

The court, in an 8-0 ruling, handed a victory to Lester Packingham, a registered sex offender due to a statutory rape conviction who had challenged the law as a violation of the U.S. Constitution’s First Amendment guarantee of free speech.

“This case is one of the first this court has taken to address the relationship between the First Amendment and the modern Internet. As a result, the court must exercise extreme caution before suggesting that the First Amendment provides scant protection for access to vast networks in that medium,” Justice Anthony Kennedy wrote for the court.

The North Carolina law, enacted in 2008, made it a felony for people on the state’s sex offender registry to use online services that can lead to social interactions with minors.

The case forced the justices to weigh free speech rights against a state’s interest in protecting its citizens, specifically from sexual abuse of minors. It was one of two victories for free speech at the court on Monday, with the justices in another case striking down a law that bans offensive trademarks. [L1N1JG0K4]

The North Carolina law banned the use of leading social media outlets such as Facebook and Twitter among others. Opponents had raised concerns that the measure could be interpreted as covering other online activity in which users must create profiles and can interact with other users. That even could include certain news websites.

Packingham was on North Carolina’s sex offender list because of his 2002 conviction at age 21 on two counts of statutory rape of a 13-year-old girl. He was convicted in 2010 of violating the statute when he posted a message on Facebook expressing his surprise at a traffic citation against him being dismissed.

The case, which tested the social media smarts of the notoriously tech-averse justices, is the latest of several in recent years that have tested free speech rights in the digital era. For example, the Supreme Court in 2015 threw out the conviction of a Pennsylvania man who made threatening Facebook statements toward his estranged wife and others in a ruling that made it tougher to prosecute people for using menacing language on social media.

The North Carolina law did not require proof that the registered sex offender intended to use a particular social media service for an illegal purpose. It also exempted chatrooms and photo-sharing sites.

Packingham was convicted of violating the law after local police saw the Facebook post he wrote upon avoiding a traffic citation. “Praise be to GOD. WOW! Thanks JESUS,” he wrote.

During February’s argument in the case, Justice Elena Kagan mentioned Donald Trump’s Twitter feed as an example of how social media has become indispensable in the political sphere.