COLUMBIA, S.C. -- A judge has tossed out the convictions of nine South Carolina black men who integrated a whites-only lunch counter during the height of the American civil rights movement.

Judge Mark Hayes on Wednesday made the ruling for the men known as the Friendship 9.

"We cannot rewrite history, but we can right history," the judge said. He then signed the order, and the prosecutor apologized to the men.

Fifty-four years ago, eight college students and one civil rights organizer were convicted of trespassing and protesting at McCrory variety store in Rock Hill.

The men's refusal to pay bail money into the segregationist town's city coffers served as a catalyst for other civil disobedience. Inspired by their courage, demonstrators across the South adopted their "jail not bail" tactic and filled jail cells. The media attention helped turn scattered protests into a nationwide movement.

W.T. "Dub" Massey and seven other students at Rock Hill's Friendship Junior College -- Willie McCleod, Robert McCullough, Clarence Graham, James Wells, David Williamson Jr., John Gaines and Mack Workman -- were encouraged to violate the town's Jim Crow laws by Thomas Gaither, who came to town as an activist with the Congress of Racial Equality.

About a year had passed since a sit-in at a segregated lunch counter in Greensboro, North Carolina, helped galvanize the nation's civil rights movement. But change was slow to come to Rock Hill. They decided to challenge matters by getting arrested in February 1961 for ordering lunch at McCrory's variety store, and were convicted of trespassing and breach of peace.

Author Kim Johnson, who published "No Fear For Freedom: The Story of the Friendship 9" last year, went to Kevin Brackett, the solicitor for York and Union counties, to see what could be done to clear their records.

"This is an opportunity for us to bring the community together," Johnson told The Associated Press before the ruling. "To have the records vacated essentially says that it should have never happened in the first place."

Brackett's request to a Rock Hill judge came too late for McCullough, who died in 2006. But some of the others returned to town ahead of the hearing to reflect on their experience.

The men's names are engraved on the stools at the counter of the restaurant on Main Street, now called the Old Town Bistro. A plaque outside marks the spot where they were arrested. And official and personal apologies have been offered to the men over the years.

In 2009, a white man named Elwin Wilson who tried to pull one of the protesters from a stool nearly 50 years earlier returned to the same counter, meeting with some of the men. They forgave him.