Wind-whipped flames blew up early Saturday, prompting epic firefights to save two of California’s signature tourist towns, but one triumphant win was soon overshadowed by defeat 30 miles away.

The frustrating scenario involved two fires — the Tubbs Fire in Napa County and the Nuns Fire in Sonoma County — and two towns — Calistoga and Sonoma — and perfectly illustrates the capricious nature of fire, and the infernal struggle against the forces of nature.

The wrenching drama played out as firefighters battled the deadliest cluster of wildfires to hit Northern California in state history — the death toll increased to 40 Saturday. Bolstered by tanker planes and bulldozers, they saved the spa town of Calistoga from the 35,000-acre Tubbs Fire only to watch helplessly hours later as the 46,000-acre Nuns Fire swooped down from the mountains east of Sonoma and torched homes in the famous Mission town.

“We’re making progress in certain areas,” said Steve Crawford, the operations section chief for the California Department of Forestry and Fire Protection, or Cal Fire, “and we’re losing acreage in other areas.”

The battle to save Calistoga from rampaging flames began at about 2 a.m. when winds — which had been promised for days — arrived with a fury. A small army of firefighters and police was all that stood between the Tubbs Fire’s uncertain path and the storied town.

It was the moment they had been waiting for.

But firefighters weren’t relying on strength alone. They were prepared to outsmart the blaze.

In the long hours leading up to the confrontation, they had used fire tankers flanked by large trucks carrying thousands of gallons of water to wet everything they could reach, running hoses into valleys and up peaks. The hope was that the damp ground would prevent anything that caught fire from spreading. That it would stop the fire from jumping too close to town.

Although Calistoga remained under a mandatory evacuation order issued Tuesday, a handful of residents remained, too stubborn to heed orders.

As the fire approached, sending embers that started spot fires, one of the army of engines on the front lines — whichever was closest to the blaze — would race over and put it out. It went this way for hours. And Calistoga was saved.

It was a different story in Sonoma.

Erratic winds drove the Nuns Fire into the town for the first time since the blazes broke out a week ago.

On West Spain Street, a block from historic Sonoma Plaza, 62-year old Jim Caroompas was jerked awake by a phone call well before dawn.

“A buddy down the street called and said, ‘Hey, we gotta move — now,’” he said. The smoke “was the thickest it has been since the fires started. It was stinging my eyes, and I had trouble breathing.”

The fire devoured houses around Wood Valley and Lovall roads — an area dotted with upscale homes, towering oaks and eucalyptus trees. Three homes on Castle Road burned to the ground just a half mile east of the Sonoma town square.

Just a few blocks away, on Half Moon Street, several more houses went up in smoke.

“The winds were bad. It was weird. They’d come in one direction and then another, just whipping everything everywhere,” said Tony Anderson, a firefighter with the Schell-Vista Fire Protection District who worked overnight in the neighborhood.

The fires burned homes about a mile east of Sonoma Plaza and the famous Spanish Mission. By daylight, 250 people had been evacuated.

“We fought it all night,” said Abel Solis, a firefighter with the North Sonoma Coast Fire Department, as he put out hot spots. “The winds were pretty bad and it lit up pretty good, but we beat it.”

As if that wasn’t enough, the rampaging Nuns Fire also spread into the beleaguered city of Santa Rosa.

The Nuns Fire made a run toward the Oakmont neighborhood of Santa Rosa, catapulting a fiery new 450-acre spot fire ahead into Adobe Canyon, off Pythian Road, near the closed St. Francis Winery and Vineyard. Helicopters dumped tons of retardant on the slopes above Ledson Winery and Highway 12, where thick, dirty brown smoke hung behind a line of trees Saturday afternoon.

The spot fire forced a hurried evacuation of homes around Highway 12 in Kenwood.

An estimated 3,000 residents of Santa Rosa were ordered out.

The renewed threat surprised Joe Titone and his wife, who returned to their home in eastern Santa Rosa’s Skyhawk community Friday after evacuating days earlier only to be awakened at 4:30 a.m. by sirens and an evacuation alert.

“Last night we thought we were in the clear,” Titone said as he watched smoke billow. “That was our mistake.”

The fire, which has gathered steam since it broke out last Sunday, was pushed by 20 mph winds out of the northeast that meteorologists warn could last through the weekend.

Bret Gouvea, a Cal Fire incident commander, said it isn’t clear whether any more homes in Santa Rosa burned on Saturday.

The defense of Calistoga highlighted the progress fire officials have made on the Tubbs Fire in Sonoma County, which was 50 percent contained, and the equally dangerous Atlas Fire, which is holding steady at 50,000 acres and was 48 percent contained.

But the blistering Nuns Fire was emerging as another big threat. It’s only 10 percent contained, and it grew to 46,000 acres after several adjacent fires combined into one.

Driving the flames is the same enemy firefighters have contended with all week — wind. Although not of the same intensity as the gales that pushed the initial fires through Napa and Sonoma counties a week ago, the gusts Saturday were enough to spread the disaster.

“We do expect winds to sustain — and maybe even increase,” said Scott Rowe, a meteorologist with the National Weather Service in Monterey.

The firefight is one of the most intensive mobilizations in California history, with more than 10,000 firefighters on the lines, including 4,000 U.S. Forest Service crew members and 12 elite hot shot crews. They are working around the clock on 17 out-of-control fires statewide, including 15 in Northern California, that have blackened 222,000 acres, or about 330 square miles.

Dave Teter, the deputy director of Cal Fire, called the multitudes “an army on the fire line in the midst of this devastating natural disaster.”

At least 22 people have died in Sonoma County, eight in Mendocino County, six in Napa County and four in Yuba County.

Thousands of missing-persons reports have been filed in the chaotic aftermath of the fires, but many of those people have been found unharmed. Napa County officials said Saturday that 74 people were still unaccounted for, and in Sonoma County the total was 223.

“We anticipate the numbers of both damaged and destroyed structures as well as lives lost to continue to increase” in the days to come, Teter said. “It’s a very dynamic situation. ... We ask all the public to be diligent, to be prepared and ready to evacuate” in the event things suddenly change.

On Saturday, Gov. Jerry Brown toured neighborhoods that had been destroyed by fire and said he was awed by the devastation.

“This is truly one of the greatest, if not the greatest tragedy that California has ever faced,” he told reporters at a briefing at Santa Rosa High School. “The devastation is just unbelievable. It’s a horror that no one could have imagined.”

Although Brown said the region was “not out of the woods,” he said progress had been made and praised the efforts of firefighters and the resiliency of the community.

Sen. Dianne Feinstein, joined by California’s junior senator Kamala Harris and Brown in Santa Rosa on Saturday, pledged that federal resources would be there to help fire victims.

“This is about the worst fire we’ve had in my lifetime,” the 84-year-old lawmaker said. “As such it ought to be treated as such, and the dollars have to come.”

With more than 2,800 homes destroyed in Santa Rosa, county health officials are concerned about toxic chemicals and substances in the wreckage.

Karen Relucio, the Napa County health officer, declared a local health emergency, a move she said would help secure state and federal help removing hazardous materials and toxic substances.

“The public should not attempt to clean up fire-related debris,” she said. “The materials are toxic.”

Chronicle staff writer Joaquin Palomino, Kurtis Alexander, Dominic Fracassa and Hamed Aleaziz contributed to this report.

Hamed Aleaziz, Kevin Fagan and Catherine Ho are San Francisco Chronicle staff writers. Email: haleaziz@sfchronicle.com, kfagan@sfchronicle.com, cho@sfchronicle.com Twitter: @haleaziz, @kevinchron, @Cat_Ho

Helping and getting help

FEMA is offering assistance to fire victims in Sonoma and Napa counties. For more information go to www.disasterassistance.gov/ or call (800) 621-3362.

The Red Cross is organizing relief efforts in the North Bay. Evacuees trying to connect with family and friends should post on the organization’s Safe and Well website: www.redcross.org/safeandwell.

Community volunteers who want to help in relief efforts can sign up with the Red Cross at http://tinyurl.com/RedCrossVolOctober2017.

Donations to help those affected by California wildfires and other disasters can be made at www.redcross.org. People can also call (800) 733-2767 or text the word REDCROSS to 90999 to make a $10 donation.

People needing to report or ask about a missing person in Sonoma County can call the county Fire and Emergency Services Department at (707) 565-3856.

For tips on how to prepare for a wildfire, go to www.redcross.org/prepare/disaster/wildfire.

For fire information in Sonoma County, call (707) 565-3856.

Donations to help fire victims can be made here: https://www.redwoodcu.org/.

To help Tubbs Fire victims, donate here: http://biturl.in/64.

Food donations can be made at the Redwood Empire Food Bank in Santa Rosa: http://refb.org/.