VENICE – Just over 500 years ago the Jews of Venice were forced to live in a segregated community that became known as the first-ever “ghetto,” a cramped but bustling community that at its height boasted nine synagogues.

But as the population of Venice has fallen over the years due to mass tourism and spiraling costs, so too have the number of Jews.

Now the chief rabbi of Venice, Rabbi Scialom Bahbout, says the city’s Jewish community has to find new ways to reinvent itself.

Only 500 Jews remain in Venice, with another 500 in nearby towns of Padua, Verona and Trieste. It is a small percentage of the country’s 30,000 Jewish population.

“Like the city of Venice itself, the community is becoming more and more of a museum,” Bahbout said. “We need a city that is alive.”

In a small square beyond the porticoes and alleyways that lead to the ghetto, Bahbout reflected on the lessons of history in his office, which sits above one of the community’s hidden gems, the Scola Ponentina, or Spanish synagogue. Completed in 1580, it was built by Sephardic Jews who sought refuge in Venice after being expelled from Spain.

The synagogue, which is still used, lies behind heavy wooden doors and has an ornate wooden ceiling, large chandeliers and a decorative stone floor. It is one of five synagogues that remain and three that can be seen by visitors on a tour of the Jewish museum.

But the Jews who remain in Venice are searching for a deeper cultural and religious experience.

“It is difficult because most young people are leaving for places where they are assured of a more comprehensive Jewish life; in Italy, that means Milan or Rome,” he said. “Many also move to Israel, Paris or New York.”

Bahbout, who was born in Libya and migrated to Italy with his family in the 1950s, said the first Jews arrived in Venice in the 10th century. As the former Venetian Republic flourished over the centuries, many Jews from Germany, Portugal, Spain, France and southern Italy sought refuge in the port city and established synagogues that reflected their different ethnicities and languages.

In March 1516 the powerful city-state ruled that the Jews were to be locked behind gates at night, forced to wear a humiliating yellow identification and deprived of owning property.

Strolling through the narrow alleys in the ghetto today, visitors see few external reminders of how difficult the ghetto residents’ lives actually were.

“At first they were not permitted to live in Venice; with the ghetto they were forced to live in a designated area,” says Bahbout. “It was like a prison.”

Nevertheless, he said Venice became a center of learning, renowned for printing and publishing Jewish books and manuscripts, and paradoxically a place where Jews were able to practice their faith.

“Life in the ghetto was vibrant because the Jews were not homogeneous. It was a melting pot,” said Riccardo Calimani, a historian who published a book about the ghetto. He is also a former president and vice president of the Jewish community in Venice.

“Through publishing they attracted intellectuals from abroad and the community became a bridge between northern Europe and Constantinople,” said Calimani, whose family arrived in Venice in 1508.

“But today they say the community is dying like the city of Venice,” he added. “It is not easy.”

The gates were finally removed from the ghetto when Napoleon Bonaparte and his troops conquered the city in 1797. Their civil rights restored, several Jews played a prominent role in Italy’s unification in the 19th century, but in 1938 racial laws introduced by Benito Mussolini deprived them of their civil rights once again.

During the Nazi occupation of Italy, 246 Jews were deported from Venice to extermination camps; only eight returned.

Last year, Venice hosted a major retrospective titled “Venice, the Jews and Europe – 1516-2016,” which drew thousands of visitors to the Doge’s Palace in St. Mark’s Square.

Bahbout said the success of that exhibition should energize the community so it can build a different kind of future.

“Even though we are a small community, we have deep roots,” he said. “We need to reinforce and strengthen those roots.”

Other cities in Italy are trying to find ways in a Catholic country to be in dialogue with their Jewish populations and to find ways to keep Italian Jews in Italy.

In January, the Catholic Archdiocese of Palermo transferred to the Jewish community there a chapel, the Oratory of Santa Maria al Sabato, which was built above the ruins of the Great Synagogue that once stood in the center of Palermo. It took place on the anniversary of the decree that demanded the expulsion of Jews from Sicily during the Spanish Inquisition.

The archbishop of Palermo, Corrado Lorefice, described the initiative as a “gesture of hope” designed to build dialogue between Catholics and Jews.