On a hot Sunday morning in Oak Bluffs, the Hon. Margaret Marshall’s words were focused on a continent and an era away: South Africa during the apartheid era, when Nelson Mandela was a source of inspiration to Ms. Marshall and so many others.

As paper fans fluttered in the pews, a full crowd at Union Chapel listened to the former chief justice of the Massachusetts Supreme Court as she recalled growing up and going to college in South Africa at a time when her teachers and friends were imprisoned, tortured and forced to leave the country because of their views and “women and men were treated as sub-human because of the color of their skin, by operation of the law.”

Ms. Marshall retired in 2010 from her position as chief justice of the Massachusetts Supreme Judicial Court. In that role she wrote the decision that paved the way for same-sex marriage in Massachusetts.

As a student in South Africa, she was elected president of the anti-apartheid National Union of South African Students. She traveled around South Africa, she said Sunday, speaking and organizing against apartheid, activities that placed her at “considerable risk” with no hope of help from the courts.

According to news reports, Mr. Mandela, an iconic leader who spent nearly 30 years in prison under apartheid and later became president of South Africa, has been in critical condition in a South African hospital.

“We wait to mourn and then celebrate a life well-lived,” Ms. Marshall said Sunday, speaking as part of Union Chapel’s summer guest speaker series.

“Who is Nelson Mandela? Why does the world, the entire world wait to mourn his death?” she asked, then answered: his humility, his incorruptibility, his morality, his love of children, a willingness to die for ideals that he held firm, and his lack of bitterness in the wake of decades of brutal treatment.

Most of all, she said, she celebrates his commitment to the rule of law, “though the apartheid government hounded him and imprisoned him for decades.”

“Etched in my memory are particular events from South Africa from those early days of liberation,” she said. In September 1995, the new constitutional; court’s justices said an act of the national congress had violated the new constitution. “It was a devastating judgement against Mandela,” she said.

Instead of being angry, Ms. Marshall said, Mr. Mandela called this a victory for South Africa, saying the democracy was working and the country should be proud.

“That is the moment that I knew . . . constitutional democracy was indeed putting down deep roots there.”

Ms. Marshall came to the U. S. in 1968 at the age of 24 with her experience in South Africa giving her more appreciation for the law.

“For those of you who are born here, you may take for granted the existence of an impartial judiciary and the ideal of equal justice under the law,” she said.

“The continued respect for the rule of law in South Africa, and it does continue, owes much to Nelson Mandela.”

Union Chapel was an apt venue for Ms. Marshall’s words. Church president Alphonse H. Carter began the church service by recalling that 143 years ago, the church founders created a place of worship for everyone.

“To have a former chief justice [speak] on the Fourth of July Sunday here in 2013 . . . it doesn’t get any better than that,” Mr. Carter said.

Flowers framing the pulpit were donated in memory of Paul E. Johnson. Ms. Marshall dedicated her remarks to Mr. Johnson, “a longtime member of this community and this chapel and my mentor at Harvard University.”

Before her sermon concluded with a standing ovation and Joyful, Joyful, We Adore Thee, Ms. Marshall shared some of Mr. Mandela’s words.

At a concert about a decade ago, she recalled tearfully, Mr. Mandela said that “it is music and dancing that makes me at peace with the world. It is music and dancing that makes me at peace with the world and at peace with myself.”

“Dance, my sisters and brothers,” she said. “It makes you at peace with the world and at peace with yourself.”