MORRO BAY, Calif.—When this quaint fishing city looked at places for a new sewage treatment plant to replace the aging one next to the beach, it proposed to stay put and rebuild by the water.

The location did not sit well with state coastal regulators, who were concerned about the threats of erosion and rising sea levels fueled by global warming.

Days before the California Coastal Commission was set to hear the case, the city turned into an unlikely ally.

During a special meeting Thursday night, the Morro Bay City Council headed by a newly elected mayor narrowly voted to side with the commission's staff, which recommended denying a permit to rebuild on the existing site.

Mayor Jamie Irons said it was time to face reality.

"Is that really the site that is viable for us as a community, as a city in the future?" he said a day after the 3-2 vote.

Even with the city's change of heart, the state coastal panel was still expected to take up the issue next week because the plant's co-owner had not withdrawn the application.

Along the 1,100-mile-coast, communities are mulling whether to relocate critical infrastructure, parking lots, bike paths and buried utility lines in a planned retreat from the ocean.

The city of Ventura, northwest of Los Angeles, in recent years tore up a disintegrating oceanfront bike route and built a new one further inland.

Nestled midway between Los Angeles and San Francisco, Morro Bay's wastewater treatment plant was erected next to a beach north of Morro Rock, a prominent volcanic feature. It sits in a floodplain and tsunami hazard zone.

In 2003, the city was ordered to modernize the facility, built in 1954. It's one of the few plants in the state with a waiver to discharge primary-treated sewage into the ocean.

The city decided it would raze the old plant and build a new one next door. Officials hired consultants to explore other locations, but settled on the existing site.

The plant serves about 13,000 customers in Morro Bay and nearby Cayucos. It's owned by the city and the Cayucos Sanitary District.

District officials did not attend the City Council's special meeting. Emails and telephone messages left with the district's interim general manager Rick Koon were not returned.

Before the about-face, the city maintained that moving the sewage plant inland would be too expensive and would lead to higher sewer bills.

Former Morro Bay councilwoman and coastal activist Betty Winholtz tried to convince the city to relocate the sewer plant during her tenure.

"It totally defies logic" to rebuild in a vulnerable spot, she said.

During the special hearing, a stream of residents implored councilmembers to side with the coastal commission. Some cited Superstorm Sandy, which inundated parts of New York and New Jersey last year, as a reason to not put a sewage plant in a flood zone.

Residents who opposed the move feared they would be burdened with higher bills.

Besides the sewage plant, there are private residences and a high school in the floodplain. But the city is currently only mulling shifting the plant.

"Maybe in the future that would be a consideration," Irons said.