Twelve years after Sept. 11, New York City is safer, but the threat remains. The New York Police Department adapted and became not just the nation’s most highly regarded police department, but also the nation’s most effective counterterrorism force.

Doing so was essential since the terror threat has evolved sharply since early 2002, when police chief Ray Kelly first sketched out his plan for countering it on a piece of paper for then-new Mayor Michael Bloomberg.

Al Qaeda’s “core,” as counterterrorism experts call the organization that Osama bin Laden headed, and its affiliates remain a threat. In May 2011, Steve Kappes, a former deputy CIA director, told an NYPD gathering of public and private security professionals that al Qaeda was the “most adaptive terrorist entity” he had encountered in his 30-year intelligence career.

Even without bin Laden, he said, its threat might not be “significantly diminished” for years to come. His words were prophetic, as last year’s Sept. 11 attacks on the U.S. consulate in Benghazi by al Qaeda-linked militants made clear.

Though tensions remain between the FBI and the NYPD, Kelly maintains that the two organizations now work together well. The police department, which once had only 12 detectives on the FBI’s Joint Terrorism Task Force, now has 120. “The major source of information for us is the JTTF,” Kelly says.

The NYPD has also negotiated protocols with other city agencies that often figure in terror investigations — New York’s vast public-health service, for instance, the police department’s partner in efforts to monitor dangerous pathogens and viruses that could be used in a terror attack.

But Kelly does worry about what he and his counterterrorism division cannot control unilaterally — for instance, the policing and protection of bridges, tunnels and the Hudson River, whose surveillance is shared with the Port Authority and the Metropolitan Transit Authority.

A related concern is the inability or unwillingness of neighboring jurisdictions to implement counterterrorism measures similar to New York’s — one reason for the NYPD’s Sentry program, which trains cops in the tri-state area in counterterrorism techniques in order to foster intelligence-sharing.

The NYPD’s priority is preventing terror, rather than responding to it. Many say privately that the Boston Marathon bombings might not have occurred had the Tsarnaev brothers lived in New York.

The NYPD would have kept track of such Muslim extremists, experts say. But the very programs that have helped thwart some 16 attacks on the city are now being challenged as unconstitutional by the NYCLU and other civil liberties groups in court.

And, of course, Kelly worries about nuclear terrorism. The NYPD has drawn up evacuation plans for the city in that scenario, but they’re of limited value. In such an emergency, the police department would have to rely on “self-evacuation” — individual decisions by hundreds of thousands of New Yorkers to leave the city, even on foot and across bridges.

Another terrorism-related anxiety for Kelly, aides say, is that the government’s visa policies and the country’s easily penetrable borders mean that he doesn’t know who’s living in New York.

In 2005, Congress passed the REAL ID act, requiring states to issue driver’s licenses that could be readily authenticated through encryption and biometrics after a background check. But many states have rebelled against implementing it, citing cost, privacy and other concerns.

Perhaps the greatest challenge to the NYPD’s efforts, however, is the way we think about terrorism. “Americans like to see conflicts as finite, with a beginning and an end,” says Brian Jenkins, the prominent terrorism guru.

“But that will not be the case in the struggle against terrorism. This challenge adapts and morphs and is constantly evolving. It won’t end. It’s hard for any individual or government agency to accept that.” Even in New York.

Judith Miller is an adjunct fellow at the Manhattan Institute, a Fox News contributor and a contributing editor of City Journal. This article was adapted from the summer 2011 issue of City Journal.