To its neighbors in the San Francisco Bay Area, the city of Vallejo, CA, has long been known for several things. There was the notorious bankruptcy in 2008. There was the ignominious honor of ranking No. 9 on the Forbes list of Most Miserable Cities and No. 2 on Newsweek's of Dying Cities in the same year (2011). There was the abandoned Mare Island Naval Shipyard, the violent crime, the squalor, the shuttered homes, the hopelessness.

One thing Vallejo was not known as: the next trendy place for Northern Californians to buy a house and raise a family.

But, remarkably enough, all that has changed. For the past two months, the metropolis has topped realtor.com®'s rankings of the nation's hottest real estate markets. As in No. 1.

Call it the latest beneficiary of the Bay Area's brutal (and brutally expensive) supply-and-demand housing market. As more and more buyers and renters are priced out of San Francisco and the surrounding towns, they've become increasingly open to new frontiers. It's led to a resurgence and gentrification in long-downtrodden Oakland. And now it's hitting Vallejo big-time.

Georgia Street in Vallejo, in May 2008, shortly after the City Council voted to file for bankruptcy. Justin Sullivan/Getty Images

Buyers are overlooking the high crime rates and poor public schools and snapping up stately Victorians and other residences in the former naval town, where the median listing price is just $345,000, according to realtor.com.

The price is still considerably higher than the national median price of $247,700 for existing homes and $306,700 for newly constructed abodes, according to June data from the National Association of Realtors® and the U.S. Commerce Department. But it's dirt-cheap compared with San Francisco, with a median listing price of $1.1 million, or Silicon Valley's Palo Alto, CA—where techies are shelling out a mind-boggling median $2 million on their treasured homes.

Vallejo's even a bargain compared with Oakland, San Francisco's still somewhat grittier eastern neighbor, with median list prices hitting $525,000.

"It still remains one of the few arguably affordable places in Northern California," says Javier Vivas, realtor.com's manager of economic research. "That makes owning a viable option in Vallejo, driving up demand."

Vallejo's woes

But despite having twice served as the capital of California (briefly, in 1852 and 1853), the city wasn't always so in demand. Its established middle- and working-class community took a big hit in 1996 when the area's major employer, the naval shipyard, closed, and thousands of workers were suddenly out of a job.

"The housing market really did bottom out at that time, because a lot of people were taking jobs elsewhere and leaving the community," says Jim Kern, executive director at the Vallejo Naval and Historical Museum. "The city has always been defined by the presence of the Navy. [But] for 20 years, we've had to carve out a new identity."

A parking lot at an out-of-business store in Vallejo, in 2009—not an atypical sight at the time Justin Sullivan/Getty Images

A little more than a decade later, the world economy tanked, the U.S. housing market cratered, and a wave of foreclosures swept through Vallejo. Without those property taxes to pay for the city's public worker pension costs, the city declared bankruptcy.

At the height of the foreclosure crisis, homes were selling for about $100,000, says Vallejo real estate agent Debbie Raynor of Re/Max Gold. She used to list foreclosed properties for the banks that repossessed them.

"Still, nobody wanted to be in Vallejo," says Raynor, adding that some of those empty homes became drug dens and havens for squatters. "It was blighted. There was a ton of crime."

Violent crime is still a problem in the city, where it is more than double the national average. There were 18 murders, 63 rapes, 363 robberies, and 1,040 auto thefts in 2014, according to the most recent information available from city-data.com.

The city's public school district is also struggling—receiving just a 4 out of 10 rating on GreatSchools.org.

So with high crime and lousy schools, how did Vallejo, with a population of about 121,000, become the nation's hottest market? Sorry to trade in clichés, but as the real estate pros like to say (and say again), it's all about one thing: location, location, location.

Vallejo's comeback

Across the board, things in Vallejo are definitely looking up.

The city is just over 30 miles from San Francisco and about 60 miles from Sacramento along the Interstate 80 corridor. And when the workweek is over, it's home to Six Flags Discovery Kingdom and a mere 16 miles from Napa and its surrounding wine country. In recent years, a "vibrant" artist community has moved into the city's downtown, heralding the opening of several small galleries, says Rich Curtola, CEO of the Vallejo Chamber of Commerce.

Residential neighborhood near the Napa River Greg Chow

Perhaps most important, Vallejo offers ferry service directly to San Francisco so commuters can get to work in the Golden City within an hour.

"People are saying, 'Jeez, I can't afford to live in San Francisco, and I can't even afford to live in Oakland,'" Curtola says. "What people are finding is there are affordable properties here that are absolutely beautiful."

The turnaround seems sudden, but it's actually years in the making.

Investors realized this early on and swooped in in 2009 and 2010 and began rehabbing foreclosures that had seen better days and flipping them, local real estate agent Raynor says.

But the days of finding real estate bargains are long over, she says. Now she's getting multiple offers and bids well over asking price, despite the continuing dearth of popular amenities such as trendy restaurants.

"It's still one of the last remaining underdeveloped areas with waterfront," says Raynor, who lives in the city.

House in Vallejo Greg Chow

And prices are only expected to continue shooting up. There are plans for hundreds of waterfront condominiums, some high-end rentals, and retail development along the Napa River, says Andrea Ouse, community and economic development director for the city of Vallejo. There are also schemes to put up hotels, a sports field, and a 3,000-seat amphitheater on the site of the Solano County Fairgrounds. There is no set date for construction yet.

"Land values are going to increase particularly over the next three to five years due to the level of investment that we are seeing now and the level of interest in potential development," Ouse says.

Mare Island's resurgence

Houses on Mare Island, on the San Pablo Bay side Greg Chow

Mare Island, the former home of Vallejo's long-deserted shipyard, is also experiencing a resurgence. The island now has about 250 homes and more than 100 businesses, says Edward Moser, a spokesman for Lennar Mare Island, the developer for a portion of the island.

The ship construction and repair firm Mare Island Dry Dock opened in late 2013 and now employs about 150 people. Touro University California moved to a 44-acre site on the island in 1999 and opened a nursing school there in 2014. Faraday Future, an electric car company, is in negotiations to open a factory and test-drive facility on a large property parcel.

Houses on Mare Island, looking west toward San Pablo Bay Greg Chow

Azuar Drive and Flagship Drive, at the outskirts of the residential area of Mare Island Greg Chow

Home for sale on Mare Island in Vallejo Greg Chow

And there are plans to put up a new ferry terminal, whiskey distillery, and 1,400 single-family houses, townhouses, condos, and rentals on the island as well, Moser says.

The Mare Island Brewing Co., which opened in 2013, is doing so well that it plans to break ground on a larger facility on the island this fall.

"Our taproom is so busy that we can't keep up," says Kent Fortner, the microbrewery's founder/owner and a proud Vallejo resident. He's seeing an influx of refugees from other, pricier Silicon Valley hubs.

"It's headed upward. You can feel it," says Fortner. "Everybody I know is relandscaping their lawns, doing a small remodel ... or they're actually thinking of buying a second home on the island as an investment to rent out."

The Mare Island Causeway bridge across the Napa River, connecting the Mare Island peninsula to the rest of Vallejo Greg Chow

The biggest challenge to the burgeoning community remains the substandard public schools, a warship-size obstacle for many professionals with children. His own two kids attend a charter school in Napa.

However, he remains optimistic about the future of Vallejo.

"It's a renaissance that has no limits," Fortner says.