Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

Intelligence and law enforcement agencies worry that a surge of violent extremists will eventually move from ISIS-controlled areas in Syria and Iraq into Western nations with the aim of committing terrorist attacks, FBI Director James Comey told Congress on Tuesday.

"The caliphate will be crushed," but hundreds of people will remain and become part of a "terrorist diaspora" in the next two to five years. "When ISIS is reduced to an insurgency, those people will try to come to Western Europe and here," Comey said in testimony before the Senate Homeland Security and Government Affairs Committee.

Read: EUROPE'S TERROR BATTLE

He urged Western European nations to take advantage of the data the U.S. has gathered on terrorism since 9/11.

The most important way to prepare for the coming "terrorist diaspora" as ISIS collapses, he said, "is to knit ourselves together, especially with our European colleagues. Our European colleagues must do that and connect themselves to us and our information better, so that we can spot and disrupt that flow when it comes."

FBI Director James Comey testifies before the House Oversight and Government Reform Committee hearing on 'Oversight of the State Department', focusing on the FBI's recommendation not to prosecute Democratic presidential candidate Hillary Clinton; on Capitol Hill in Washington, D.C., July 7, 2016. MICHAEL REYNOLDS / EPA

"That's the threat we've been preparing for since 9/11 — the external flow of terrorists looking to come into our country," he added.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Comey testified alongside Homeland Security Secretary Jeh Johnson and Nicholas Rasmussen, director of the National Counterterrorism Center, at a hearing examining threats to national security 15 years after the 9/11 attacks. The hearing took place just over a week after bombings in New York and New Jersey and a separate stabbing attack at a Minnesota mall.

Rassmussen said the U.S. watchlisting system "allows us to have confidence that if we have an identity, we are very likely to prevent an individual from getting into the United States."

Nonetheless, he said, the system is based on names and needs to depend more on biometric data that can't be fooled with counterfeit documents.

While fewer people are trying to travel to Syria to join ISIS, homegrown terrorists, inspired by ISIS propaganda, remain a central concern for the FBI, Comey said.

The dropoff began late last summer. At the peak, the FBI was seeing from eight to ten people a month trying to join the caliphate. Now it's averaging between none and one.

Johnson said terrorist threats have evolved, moving from terrorist-directed attacks "to a world that also includes the threat of terrorist-inspired attacks" in which individuals who live in the U.S. are "self-radicalized" to attack their own country.

Suspected New York-New Jersey bomber Ahmad Khan Rahami, referenced in a journal slain American-born al Qaeda cleric Anwar al-Awlaki, Osama bin Laden and Nidal Hasan, the Army psychologist who murdered 13 people at Fort Hood in 2009.

Comey suggested that Rahami's father did not tell the FBI that he was worried his son was a terrorist. Comey added that the FBI is going back to thoroughly review how it assessed Rahami two years ago.

Ahmad Khan Rahami in a police mugshot. Union County, N.J., Prosecutor's Office

Johnson says that by their nature, terrorist-inspired attacks and terrorist-enabled attacks are difficult to detect by intelligence and law enforcement communities, can occur with little or no notice and in general make for a more complex homeland security challenge.

That complexity includes recent hacks into U.S. election systems — incidents which prompted the head of the National Security Agency to sound the alarm about concerns about the potential for Russia to harm the U.S. electoral process in the upcoming general election.

On Tuesday, Homeland Security Secretary Jeh Johnson said "I don't believe we have reached a determination" that the attacks are coming from one particular country. Johnson noted that the U.S. has seen and officials are investigating "a limited number of instances" where cyber intruders have tried to get into state election agencies, though not to change votes.

Comey also acknowledged that Hillary Clinton's former chief of staff, Cheryl Mills, was given limited immunity by the Department of Justice in the FBI's investigation into the use of the former secretary of state's private email server. He said Mills' lawyer asked for what's known as active production immunity for the laptop —an agreement that DOJ could not use any evidence from that computer against her.

It's a "fairly common tool in criminal investigations," he said.

He said another reason for going that route is because Mills is a lawyer and trying to get it through conventional subpoena might have produced months of litigation.