They were dreaming of a white flag.

A nine-hour standoff with a gunman barricaded in a Pennsylvania home ended with a little yuletide cheer — a SWAT team member singing “White Christmas,” according to a report.

Relatives called police Christmas night when Nathaniel Lewis, 34, a member of the Pennsylvania National Guard, started acting erratically because his wife asked for a separation, CBS Philly reported.

When cops arrived at the East Vincent Township home, they learned that Lewis had a gun — and called in the local SWAT team to help defuse the situation.

But Lewis refused to come out of his home, took out his rifle and fired some 20 shots at cops from a second-floor bedroom, striking the sides of an armored police vehicle, a civilian’s vehicle and a nearby home, the station reported.

Finally, Lewis demanded nine hours later that a negotiator sing him “White Christmas.”

It took four verses of the Bing Crosby carol for Lewis to come out.

“This is as close to a Christmas miracle as you’re gonna get,” Chester County DA Tom Hogan told the outlet. “Everybody got to go home to their families that day. The SWAT team got to go to their families. The defendant was taken into custody, but he wasn’t killed.”

Hogan even showed up at the scene to hand out Christmas cookies to “cold and tired” SWAT members, according to the report.

Lewis, who was finally taken into custody by 7 a.m. Wednesday, was charged with multiple counts of attempted homicide and aggravated assault, among other offenses. He remains at the Chester County Prison.