BANGOR, Maine — Its name was supposed to be Sunbury but because of a misunderstanding, it became known as Bangor.

How Bangor got its name was the subject of a play that was staged Friday at City Hall as part of the city’s yearlong 175th anniversary celebration.

“It’s very strange how Bangor got its name,” City Council Chairman Gerry Palmer told an audience of third-graders, teachers and parents from Fruit Street School before the second of two performances staged Friday.

“Many communities have songs named after them,” he said, singing snippets of “My Kind of Town” (Chicago), “Theme from New York, New York” and “I Left My Heart in San Francisco” to make his point.

“You know how Bangor’s different? Bangor’s different because Bangor is named after the song. And it was an accident. It happened because it was playing.”

Written by Palmer, the play — “How Bangor, Maine, got its name — 1791 or The Rev. Seth Noble vs. the Commonwealth of Massachusetts” — depicts the chain of events in early 1791 that led to the city’s being named “Bangor.” That was the name of the Welsh hymn that the Rev. Seth Noble happened to be singing when the clerk of the General Court of Massachusetts asked him what name was to be given to the small, rural village that one day would become Maine’s third-largest city.

John Hancock, then governor of Massachusetts, signed the historic town incorporation document into law on Feb. 25, 1791. The name stuck and the village formerly known as Plantation of Condeskeag, named after the Condeskeag (now Kenduskeag) Stream, has been called Bangor ever since.

The play was performed twice Friday, once at 11 a.m. and again at 1 p.m., by an all-volunteer cast made up of city officials, staff and other adults, all of whom portrayed historical figures, and three Fruit Street School third-graders, who portrayed city kids from modern times.

Playing key roles in the play were City Councilor Rick Bronson as Noble and Planning Officer David Gould who was tapped for the role of the clerk who penned “Bangor” into the space where Sunbury was supposed to go.

Bronson portrayed Noble as distracted and a little bumbling, though some versions of the story claim the clergyman had been tippling when he submitted the incorporation papers. Gould played the clerk of the Massachusetts General Assembly as a snooty, know-it-all, city type less than impressed with the backwater minister.

“I did that to show the tension between [the territory that would one day become the state of Maine] and Massachusetts,” Palmer said after the afternoon performance.

Other re-enactors were: Bill Sullivan, Gibran Graham, Nick Bearce, Bill Simms, Richard Shaw and Palmer. The pupils who performed were Isabelle Morris, Jaiden McDonald and Maia Campbell.

In another anniversary event Friday, the 175th anniversary time capsule — a handmade 3-foot-by-2-foot oak box built and donated by Palmer’s father, Gerald M. Palmer — was officially sealed. On Monday it will be placed in a vault at City Hall. It will be opened in 2034, when Bangor marks its bicentennial, Palmer said.

Exactly what’s in the box, however, remains a closely guarded secret. Palmer said the contents are being kept under wraps so as not to spoil the surprise when the box is opened.

He did say that the box contains 397 items, including books, artwork by Fruit Street School pupils, a coin, CDs and DVDs, to name a few.

Bangor residents who missed the play can see it in coming weeks on Channel 7 on the Time Warner Cable network, Palmer said.