Authorities were investigating terror links after a government worker and his wife shot up his San Bernardino, Calif., office party Wednesday, killing 14 people.

Syed Farook, 28, a devout Muslim, stormed out of the festivities and later returned with his new wife, Tashfeen Malik, 27. Both wore dark tactical gear and masks while toting assault rifles and handguns, police said.

The murderous duo sprayed bullets inside a conference room, slaughtering colleagues who earlier this year had thrown a shower for their new baby.

In addition to the dead, 17 were seriously wounded.

No motive was immediately determined, but the Joint Terrorism Task Force was investigating and the city’s police chief declared early Thursday, “We have not ruled out terrorism.”

“This was not a casual workplace argument,” one law enforcement source told The Post. “It’s a well-planned and thought-out attack.”

The killers sped away in a black SUV from the Inland Regional Center, a state-run facility for developmental-disability services.

Hours later, cops went to Farook’s home in nearby Redlands, where the couple fled in the SUV. Officers eventually cornered the Yukon Denali on a quiet San Bernardino street and riddled it with bullets during a shootout that left Farook and Malik dead as blood pooled in the road.

Jesus Gonzales, 36, said his house was hit during the gun battle while his wife was inside.

His wife “called me frantically saying she’s hearing gunshots going off. Everywhere. And that she’s scared. And that she heard noises in the house, like it’s hitting the house,” he told the San Bernardino Sun. “She ducked down and said she heard more than 100 rounds.”

Authorities said the killers had thought through the massacre before heading to the facility at about 11 a.m. local time.

“Preliminary information indicates that these were people that came prepared, that they were dressed and equipped in a way to indicate that they were prepared,” San Bernardino Police Chief Jarrod Burguan said.

“And they were armed with long guns, not handguns.”

He later added, “They came in with a purpose — they came in with an intent.”

Burguan said he could not rule out that a personal conflict led to the shooting, the LA Times reported.

“There was some type of dispute” at the banquet before Farook left the event angrily, Burguan said. He later returned with Malik and they opened fire.

Law enforcement authorities said they recovered four firearms, at least two of which had been legally purchased, the paper reported.

Farook, born in the United States, met Malik while on a recent trip to her native Saudi Arabia, the LA Times said. He had met her online, the paper reported.

The Council on American-Islamic Relations (CAIR) said Farook left his 6-month-old child with his mother Wednesday morning, claiming he had a doctor’s appointment.

Farook’s brother-in-law, Farhan Khan, said at a press conference with the Orange County chapter of CAIR: “I have no idea why would he do that. Why would he do something like this? I have absolutely no idea.”

Farook made $51,000 a year as an environmental health specialist for the county.

A co-worker at the San Bernardino County Department of Public Health said Farook was a reserved man who had just returned from paternity leave.

“He was very quiet,” Griselda Reisinger told the LA Times. “I would say hi and bye, but we never engaged him in conversation. He didn’t say much at all.”

Reisinger, who left the agency in May, said there were a lot of workers unhappy with management in the department.

But Farook “never struck me as a fanatic, he never struck me as suspicious,” she said.

Patrick Baccari, who shared a cubicle with Farook, said his colleague appeared to be “living the American dream” with his new wife and baby.

Baccari and another worker said Farook rarely started a conversation but was well-liked.

Baccari said that when Farook disappeared just before the photo session at the party, someone asked, “Where’s Syed?”

The slaughter took place inside the largest conference room at the facility, where the party was being held.

The shooters specifically targeted a group from the San Bernardino County Department of Public Health, according to Inland board president and chief executive Marybeth Feild.

Terrified social workers locked their office doors, hid in bathrooms and ducked under desks as gunshots rang out.

Several people texted loved ones as they sought cover.

“People shot. In the office waiting for cops. Pray for us,” Terry Petit’s daughter texted him. Her fate was unclear.

Cops who arrived on the scene never exchanged shots with the attackers, who might have fled by then.

A rifle with a black nylon case was found on South Waterman Avenue, not far from the center.

Meanwhile, the sidewalks and streets outside the building were a bloody, chaotic mess, with wounded victims being treated on the ground as others were hurried into ambulances.

Dozens of people left the building in single-file lines with their hands up, to ensure the killers hadn’t embedded themselves among them.

Most of the evacuated employees were taken to the Rock Church & World Outreach Center in San Bernardino.

Some of the wounded were being placed in the backs of pickup trucks to be taken to hospitals.

Arrowhead Regional Medical Center reported taking in six patients, while Loma Linda University Medical Center said it was treating another six.

Hordes of law enforcement officers descended on the facility in the aftermath, spending hours sweeping for explosives.

A bomb squad detonated one suspected explosive device using a robot, according to a federal law enforcement official.

Additional reporting by David K. Li and Post wire services