WASHINGTON — Times Square bomb suspect Faisal Shahzad drove to a New York airport with a gun purchased in Connecticut two months ago, New York Police Commissioner Raymond Kelly said today.

Investigators have said a gun was discovered in the car Shahzad left at John F. Kennedy International Airport. He was hauled off a Dubai-bound plane he boarded Monday night despite being under surveillance and placed on the federal no-fly list.

“We know he purchased a weapon in Connecticut in March,” Kelly told a hearing of the Senate Homeland Security and Governmental Affairs Committee.

Kelly also said the hidden vehicle identification number on the suspect’s SUV was crucial to identifying Shahzad, while databases were key to linking telephone numbers that led authorities to the suspect.

The 30-year-old son of a retired official in Pakistan’s air force, Shahzad was charged Tuesday with trying to blow up a crude gasoline and propane device inside the parked SUV amid tourists and Broadway theatergoers.

Kelly and New York Mayor Michael Bloomberg testified in favor of legislation that would make it more difficult for suspected terrorists to buy guns.

According to the criminal complaint filed Tuesday, Shahzad drove a black Isuzu Rodeo with tinted windows; he drove it in April to a Bridgeport, Conn., parking lot to purchase the Pathfinder he admitted driving into Times Square, the complaint said.

He fled to the airport Monday from Connecticut after becoming spooked by news reports that authorities were seeking to arrest a man of Pakistani descent in Connecticut, two people familiar with the probe told The Associated Press Tuesday.

Asked about lessons learned from the failed bombing attempt, Bloomberg said that preparation for such an incident paid off: Street vendors were vigilant and responders reacted according to their training.

He praised first responders for quickly moving people from the area and the fire department for their rapid response.

And he warned that more attacks will certainly occur in New York.

“We are a target. We are going to be a target again,” he said.

Kelly said the investigation “was clearly a team effort” between city and federal authorities. “We worked seamlessly on this case. The relationship is strong and a very productive one as this investigation showed.”