FBI Director James B. Comey, left, and New York Police Department Commissioner William J. Bratton, seen in December, have greatly improved the working relationship between their agencies. (Andrew Burton/Getty Images)

— In the long, bitter and testosterone-rich rivalry between the New York Police Department and the FBI, few things aggravated the G-men more than the repeated towing of their cars by the local cops. And the practice was one of the first things that NYPD Commissioner William J. Bratton banned when he took over in late 2013 and tried to defuse tensions with his most important counterterrorism partner.

Relations between the NYPD and the FBI, never warm, deteriorated sharply after the Sept. 11, 2001, attacks when the country’s largest police force transformed its intelligence division and expanded its counterterrorism work well beyond the city limits, brushing up against the bureau’s prerogatives.

But Bratton, who has hired some prominent FBI personnel into the NYPD, has purged much of the bad blood, drawing praise for ending turf wars that potentially endangered the city.

“If there is a glitch in this one . . . that’s going to be a big deal,” said John Miller, the NYPD deputy commissioner of intelligence and counterterrorism who also spent years working for the FBI.

Diego G. Rodriguez, a Queens native who is in charge of the FBI’s New York field office, said that “it’s a no brainer to work together,” adding: “I don’t know how to do business any other way. I am from here.”

[In New York, a turf war in the battle against terrorism]

Under the previous police commissioner and his intelligence-division chief, the NYPD saw the FBI more as rival than partner.

The NYPD tried to limit the FBI’s view into its intelligence operations, raising concerns among federal agents that some investigations were not being done properly.

But with the arrival of Bratton, FBI officials now have a seat at the NYPD’s weekly intelligence collection meeting. The FBI and NYPD have also swapped intelligence analysts as part of a three-month-old pilot program; previous exchanges involved investigators.

Miller said the relationship benefits from his time working at the FBI. “It helps to speak fluent FBI,” he says.

The NYPD also hired Peter Donald, a former FBI spokesman in New York, as director of communication, a key role in handling crises and reducing friction.

More important, the two sides are working together, officials said. Last summer as the number of terrorism suspects linked to the Islamic State spiked, the Joint Terrorism Task Force struggled to keep pace and found itself with more suspects than surveillance teams. Miller then shifted some of his teams doing lower-priority cases to help out.

“We benefit from John,” said Carlos Fernandez, one of the FBI’s most experienced counterterrorism agents, who overseas the Joint Terrorism Task Force, the largest in the country.

The FBI also benefits from the NYPD. The police department has more than 100 officers on the task force, working among the 17 counterterrorism squads. About 25 percent of the officers on the task force are from the NYPD.

Also helping to soothe relations are changes in the way the NYPD intelligence division conducts its operations, a flash point in previous years.

After Muslims in New York sued the police department, saying their constitutional rights were being violated by police surveillance activities, the NYPD, in response, codified certain investigative practices, bringing them closer in line with the FBI’s. The NYPD admitted no wrongdoing but paid attorney fees.

Still, some of the old tensions can resurface.

When a Muslim convert attacked four NYPD officers with a hatchet in 2014, Bratton called the incident a “terrorism act.” Police officials pointed to suspect’s extensive online history, but the FBI was more skeptical because his last overt contact in the days preceding the attack was with a black extremist not connected to a terrorism group.

Police officials were irritated that the FBI didn’t immediately back their assessment, a former bureau official said. FBI Director James B. Comey later said, “There is no doubt it was terrorism.”

“We had that conversation and moved on,” Miller said. “We made our point.”

Miller added that disagreements are inevitable, but they don’t spill into the tabloids as they used to, with each side sniping at the other.

“It’s a collective result of all this lowering of testosterone,” Miller said.

Perhaps the best evidence that the FBI has buried its grievances was the promotion in June 2014 of Paul Ciorra to become the intelligence division’s chief of operations.

Ciorra was at the center of one of the worst moments in NYPD-FBI history when police officers, without informing the bureau, approached an imam about a terrorism suspect in a plot to attack the subway system. The imam tipped off the suspect and enraged FBI agents who feared the investigation had been compromised. While not at fault, Ciorra was blamed and sent to the highway division.

When Miller was considering candidates for the job in the intelligence division, he called the FBI to see whether Ciorra was still radioactive. He was told that it was all in the past.