The FBI is investigating whether the online courtship of the future San Bernardino mass murderers was a match made in hell by a terror group — to set in motion the radicalized duo’s evil plan, director James Comey said on Wednesday.

Comey told a Senate Judiciary Committee that investigators do not yet know if a group like ISIS hatched the love-and-hate match between jihadists Syed Rizwan Farook and Tashfeen Malik.

In response to a question by Sen. Lindsey Graham (R-SC) about whether their marriage was “arranged by a terrorist organization, Comey said: “I don’t know the answer to that yet.”

“Do you agree with me that if it was arranged by a terrorist operative of an organization that is a game-changer?” Graham said.

“It would be a very, very important thing to know,” Comey responded about the possibility that a terror group arranged a marriage and infiltrated the US using the K-1 fiancee visa system.

“That’s why we’re working so hard to understand it,” he said.

The top G-man also said that Farook, 28, and Malik, 29, were radicalized at least two years ago and planned their evil martyrdom scheme long before they were engaged and before she applied for her visa.

The couple — who lived in a two-bedroom townhouse with their 6-month-old daughter and Farook’s mother — killed 14 people and wounded 21 during a holiday party Dec. 2 at the Inland Regional Center in San Bernardino. They were killed about four hours later in a shootout with police.

The FBI had previously said only that the two had been radicalized for “quite some time.”

Malik, who lived most of her life in Saudi Arabia, moved from Pakistan to the US in July 2014. She married Farook on Aug. 16, 2014, in Riverside, Calif. He was born in Chicago in 1987 and raised in Southern California.

“San Bernardino involved two killers who were radicalized for quite a long time before their attack,” Comey said about the couple.

“Our investigation to date shows that they were radicalized before they started courting or dating each other online, and as early as the end of 2013, were talking to each other about jihad and martyrdom before they became engaged and married and were living in the US,” he said.

“We also believe they were inspired by foreign terrorist organizations. We’re working very to understand exactly their association and the source of their inspiration,” he said. “We’re working very, very hard to understand whether they had other plans — either for that day or earlier.”

A US government source familiar with the shooting probe said Farook may have been plotting an attack in the US as early as 2011, Reuters reported.

Comey also said his agents are “still sorting out” whether ISIS, which declared the duo its “soldiers,” masterminded the San Bernardino attack – but added that his agency still believes they self-radicalized.

He confirmed that Malik posted a “bayat,” or pledge of allegiance, to ISIS leader Abu Bakr al-Baghdadi the day of the attack.

“ISIL has embraced them. … So ISIL’s inspiration may well have been part of this,” he said, using another acronym for the group.

Under questioning, Comey also said he “doesn’t have reason to believe” that ISIS has already set up terrorist cells in the US.

“They are trying to do two things,” he said. “They are trying to motivate people already in the United States to become killers on their behalf. They would very much like to as they aspire to be the leader in the global jihad [and] send people here to conduct attacks. It’s that second piece that we have not seen yet.”

He also declined to say what role, if any, encrypted communications played in last week’s massacre.

Comey said he remained concerned that terrorists and others were using technology to evade detection.

“Increasingly, we are unable to see what they say, which gives them a tremendous advantage,” he said.

Meanwhile, Sen. Chuck Grassley (R-Ioway) said Malik may have provided an incorrect address in Pakistan on her visa application to hide her family’s ties to radical Islamists in the Punjab area, the LA Times reported.

“This is yet another example of the failure of the screening process for those entering the United States,” said Grassley, chairman of the Senate Judiciary Committee. “Our government apparently didn’t catch the false address in Pakistan she listed on her application or other possible signs that she was radicalized or an operative.”

Two government sources told the paper that Malik apparently used the name of a neighborhood or street near her home in Pakistan.

But others who have seen the visa application think she might have provided the erroneous information either to avoid getting exposed because of her relatives’ ties to militant groups or because she was confused by the application form, the LA Times reported.

With David K. Li and Post Wires