NEW YORK (AP) – The Beth Hamedrash Hagodol synagogue is one of New York’s treasured temples – a Lower East Side landmark that has served as a house of worship for Jews dating back to the 1800s.

But the future of the 154-year-old synagogue is in doubt.

Its walls are cracking. Its ceiling is crumbling. Prayer books are rotting.

Sensing a chance to profit, developers have begun to circle the building, offering millions of dollars to turn part of the temple into condos.

Resisting such deals has become harder and harder for those who run such fading temples. Amid New York’s supercharged real estate market, temples with dwindling congregations that are forced to maintain large, aging buildings must decide – sell or hang on.

“Taking the money is very tempting,” said Marc Angel, a senior rabbi at Shearith Israel, the oldest Jewish congregation in North America, founded in 1654. “But the guiding rule is don’t give up on a synagogue. If you do, it should be given up to a good cause. It shouldn’t be turned into apartments or a movie theater. But in reality, it’s difficult for communities to always follow that standard.”

In the case of Beth Hamedrash Hagodol, Rabbi Mendel Greenbaum has shunned the developers, instead hoping to raise nearly $3.5 million to restore the synagogue. Developers, meanwhile, have offered to turn the main part of the building into condos while restoring a sanctuary in the basement.

“I’ll hang on until the Meshiach comes,” Greenbaum says.

Over the years, shifting demographics have left many New York synagogues forsaken – only to be revived later as apartments, mosques, churches and a Buddhist temple.

On the Upper West Side, the rundown Temple B’nai Israel was demolished recently to make way for an apartment building.

In the East Village, three temples were converted into residential space – the Star of David or Hebrew inscriptions still visible on their facades. One of those is the Eighth Street Synagogue that Clayton Patterson, a local artist and preservationist, fought unsuccessfully to save in 1996. “Each one of these cycles just wipes out these synagogues and buildings of importance,” he said.

Two temples in Brooklyn were sold in the last three years. One is now a mosque, and the other was flattened to make way for a yeshiva that was never built. Members of their congregations, including one of the rabbis, have tried to halt the sales, said real estate lawyer Brian Burstin, who represented them.

“They are land grabs,” he said. “In the olden days, the synagogues would close because the neighborhoods would change. The synagogues would be sold at a nominal price because there was just no value. Now, they are transferred for significant sums of money.”

Burstin said the synagogues belong to the religious corporations that founded them, but they fall under the control of the rabbis or officers once the original congregations die off.

Temple sales must also be approved by state officials and the courts, and the money has to be used for the congregation if it’s going to move, or go to a charity. But there’s very little oversight, Burstin said, once the sale closes.

At the turn of the last century, there were more than 500 synagogues in Manhattan alone, experts say. But decades later, when Jews began moving to the suburbs, many of those temples fell by the wayside.

“It’s very hard to maintain these congregations when there is no new blood coming in,” said Oscar Israelowitz, author of “Synagogues of New York City” and “Guide to Jewish New York City.”

“There were so many left behind, it’s overwhelming.”

In January, the roof collapsed at the roughly 150-year-old First Roumanian-American Congregation – once known as the “Cantor’s Carnegie Hall” because of its stellar acoustics. “It’s a very sad story,” said 78-year-old Morris Brenner, who worshipped there for 46 years. “It’s a holy place.”

The situation is particularly acute in the rapidly gentrifying Lower East Side – a section of Manhattan that once had hundreds of thousands of Jews and scores of temples. The synagogues were at the center of Jewish life, helping immigrants find their way in a new country.

Now, the Jewish population hovers around 50,000, and there are only two dozen or so synagogues remaining, ranging from grand structures like Beth Hamedrash to one-room temples called stieblach, said Joel Kaplan, executive director of the United Jewish Council of the East Side.

“Most of them probably need an infusion of cash,” Kaplan said. “There is a sense of urgency.”

The developers know this, rabbis say. “They are always circling,” said Rabbi Azriel Siff of Chasam Sopher, a structure built in 1853.

About four years ago, Siff recalled a man holding a briefcase who approached him one Friday night after services.

The man said: “What will it take to get this building?”

The temple, Siff told him, wasn’t for sale.