In the midst of a housing crisis, California lost 13,200 homes last year — many destroyed in wildfires — but came out ahead with the net addition of 85,000 housing units, according to a demographics report released by the state Tuesday.

The state also saw a net addition of 309,000 residents, including newborns and migration from other states or countries — with the highest numbers of new Californians settling in Los Angeles, San Diego and San Francisco.

The report, by the California Department of Finance, says the state population now stands at 39.8 million and the housing stock at 14.2 million units.

Of the 482 cities in California, 421 increased their population, 57 saw reductions, and four remained the same last year. Flame-ravaged Santa Rosa grew by two-tenths of a percent, but that was only because an unincorporated area called Roseland, with 4,500 residents, was annexed last year. Santa Rosa lost 3,081 housing units in the Tubbs Fire.

The report shows that the long-term trend of steady population growth has apparently slowed, at least compared with the 333,000 average yearly growth seen since 2010, when the state’s population was 37.2 million.

Bill Schooling, the chief of demographic research for the state Department of Finance, said California has added more than 2.5 million residents since the 2010 census.

“You read a lot of negative things, but California still attracts people,” said Schooling, referring to the wildfires and high housing costs in the state.

In housing, San Francisco added 4,464 units while 10,000 more people moved in, bringing the city’s population to 884,000. The city by the bay had the state’s third highest total population gain, behind only Los Angeles and San Diego. San Jose, which added 8,500 people, was fifth.

Of the 10 most populated cities, Sacramento had the highest population growth rate — the percentage of new residents compared with the overall population — with 1.43 percent, and the fastest-growing counties were in Central California.

Merced, which added 4,900 people, or 1.8 percent, had the highest growth rate, followed by Placer and and San Joaquin counties.

Mark Hendrickson, the director of community and economic development for Merced County, attributed the fast growth to stepped-up housing construction, lower housing prices and the fact that the area is known as the gateway to Yosemite.

The rapid growth of UC Merced and Google’s driverless car spinoff known as Waymo, which operates on 91 acres leased from the county, are big incentives for people looking to move into the area, he said.

“The San Joaquin Valley as a whole is really primed to be California’s next frontier,” Hendrickson said.

The report documented a 2.6 percent drop in housing in Sonoma County, a 1.1 percent reduction in Napa County and a 1 percent drop in Mendocino County from the fires.

“We were having a housing shortage that mirrored the rest of California before the fires,” said Margaret Van Vliet, the executive director of the Sonoma County Community Development Commission. “In total, we lost about 5,300 units of housing, so for sure we were the most fire-impacted county in the state.”

Between 2010 and 2016, an average of 5,500 housing units were demolished statewide.

Mark Setterland, Santa Rosa’s chief building official, said a lot of people left the area after the fires and many of those who lost homes were underinsured.

“We lost a lot of homes from the fire and we are in the process of slowly coming out of that,” Setterland said. “It’s a real tough time.”

Sonoma and Napa counties also saw their populations go down slightly. They were by far the largest counties to see reductions. Most declines were in remote counties in the mountains, according to the report.

“I think there is still a lot of housing need and we expect housing growth,” Schooling said. “The population is growing faster than the number of houses.”

Peter Fimrite is a San Francisco Chronicle staff writer. Email: pfimrite@sfchronicle.com. Twitter: @pfimrite