WASHINGTON — In a 7-2 decision, the U.S. Supreme Court on Thursday struck down Minnesota's century-old restriction on what people can wear to the polling place on Election Day, handing a victory to challengers who said the law was too broad and difficult to enforce.

The ruling casts a cloud over similar voting-day laws in nine other states.

Minnesota banned wearing T-shirts, hats, buttons and any other clothing displaying a political message. The state defended the measure as necessary to preserve a safe voting environment, free from intimidation, and said its law was a natural extension of the court's 1992 ruling that outlaws displaying or distributing campaign materials within 100 feet of the entrance to a polling place.

But Minnesota went further, prohibiting clothes or buttons that mention not only a candidate, a political party, or a ballot issue, but also any group with recognizable political views, such as the Tea Party or MoveOn.org.

When Andrew Cilek showed up to vote in 2010 wearing a "Don't Tread on Me" T-shirt and a button that said "Please ID Me," he was told to cover them up or take them off before he could cast a ballot. He was finally allowed to vote after a poll worker took down his name and address for possible prosecution, but he was never charged.

Delaware, Kansas, Montana, New Jersey, New York, South Carolina, Tennessee, Texas, and Vermont have laws similar to Minnesota's. South Carolina also has a restriction, but it applies only to what can be worn inside the polling place by candidates themselves, not voters.

The National Association of Counties and other local government groups, in a friend-of-court brief, urged the court to uphold the law, saying it helps cut down on Election Day delays and fights. "For all the progress the United States has made in the past century, polling-place problems are still widespread," the group said.