A 52-year-old Delaware County man who had posted rambling rants and violent threats against police was shot and killed by officers Tuesday as they tried to arrest him in Drexel Hill.

When officers from three departments confronted Joseph A. Pacini of Clifton Heights and ordered him to get out of his car, he instead gunned his Nissan sedan into reverse and struck a police vehicle, according to Upper Darby Police Superintendent Michael Chitwood.

Five officers then opened fire.

"The officers were in fear of their lives and did what they had to do," Chitwood said. "He threatened to kill police, threatened to kill FBI agents."

The shooting near the intersection of Garrett Road and Shadeland Avenue erupted as rush hour was beginning in a well-traveled section of Drexel Hill. Stray bullets apparently shattered the front door of a bank branch and hit the window of a medical office, but no one else was injured.

It was not clear if Pacini was armed, although Chitwood contended he used his car as a weapon. Chitwood said that when Pacini slammed the Nissan into the police cruiser, he narrowly missed Clifton Heights Police Chief Tim Rockenbach.

Pacini had a history of mental illness and commitments, according to Chitwood. And he had made clear in YouTube rants that he was prepared to kill or be killed.

"There is no way that I am going to allow anyone to take my freedom away again, OK?" Pacini said in one video, recorded Monday. "Believe it. It's a fact. So I will immediately take out whomever attempts this on the spot. That means you'll have to kill me on the spot."

Court records show Haverford Township police lodged charges Tuesday against Pacini of terroristic threats, harassment, and other offenses. According to a source, Haverford police first learned about Pacini on Monday, when an employee at the LA Fitness club on West Chester Pike called to report a member acting "irrationally." An officer later reached out to Pacini by phone.

In his YouTube videos, Pacini replayed a message he received Monday from Haverford Detective Albert M. Hufnal about the incident at the fitness club. Then, looking into the cameras, he unleashed a response:

"Clearly these guys want me dead or in prison, and there's no way in hell I'm going back in prison. No [expletive] way. So to the police, to the FBI, to the CIA agents, I'm not taking a fall for my family anymore, OK? This time, the Sicilian code is now busted. I'm opening my mouth, right here, right now, at 5:37 p.m. on Monday, Dec. 29, 2014, this is my coming-out party.

"So you're going to try to bring me down? I will [expletive] kill you and your whole [expletive] family, all right? So go ahead and [expletive] with me, all right? Try it."

The message also included rambling references to a popular singer-songwriter: "And this is where Sara Beth Bareilles comes in, cause she has to step up to tell the world these charges are false, No. 1. And then, No. 2, get me out of here, because I'm going to be dead or in prison within the next 12 hours."

In a second video posted Monday, Pacini repeated the threats: "There will be a lot of bloodshed and a lot of eyewitnesses, and I'll probably go down . . . and that's the last thing you want. . . . Just kill me. That's the easiest option. Have your people kill me. That's it. Put a gun to my head, look me in the eye if you can find one man amongst your people, and just pull the trigger and murder me like the pigs that you are, OK?"

A third and last video was apparently uploaded just minutes before Pacini's confrontation with police.

"Hey Matt, Joe Pacini here, it's 4:04 p.m.," it began in an apparent reference to Hufnal. "Listen, man, I'm heading out, so you're not going to be able to get back to me. I'll be in the gymnasium, but before you decide to load up your police wagon and come to the gym and arrest me, I highly recommend that you view the two messages, video, voice mail messages, that I uploaded to my YouTube account. So check out both those videos, and before you do anything, respond to me, OK? I'm just going to the gym to work out. And, hopefully, there will be no problems."

Hufnal is listed as arresting officer on the court documents. But it is unclear if he had a role in the shooting. Chitwood said the officers who fired their weapons included two from Haverford, two from Upper Darby, and one from Clifton Heights. He did not name them or say which fired the fatal shot.

George Wilkie, 29, said he was sitting by the window at Marathon Pizza & Grille on Garrett Road, where he works as a delivery driver, when he heard what he thought were fireworks.

"But it was actually gunfire," he said.

Hours after the shooting, police vehicles from Upper Darby and Haverford were still on the scene, and several roads around the intersection were blocked. Yellow evidence markers were placed about a car. A medical examiner's van was parked nearby.

It's unclear if Pacini had spent time in prison. Court records show he was arrested in Philadelphia twice in the last decade, most recently in February 2009. That resulted in a guilty plea to disorderly conduct in April 2009, which was dismissed on appeal in August 2009. He had also been charged in 2005 with terroristic threats, possessing instruments of crime, simple assault, false imprisonment, and recklessly endangering another person, but those charges were all withdrawn.

Records suggest he once lived in Philadelphia, but had moved in recent years to a Clifton Heights apartment where his parents had lived.

There was no answer at the apartment Tuesday night. Neighbors Jack and Mary Johnston said Pacini's parents had lived in the apartment a long time ago but that his father died years ago and his mother moved out within the last year.

Pacini moved in during the summer of 2013. "All of a sudden, he just showed up one day and moved in with his mother," Jack Johnston said.

They said the mother and son fought regularly, and that they knew the younger Pacini was a gym regular.

"He was a little strange," Mary Johnston said, without elaborating.

610-313-8111 @MariSchaefer

Contributing to this article were Inquirer staff writers Ben Finley, Aubrey Whelan, Jason Laughlin, and Laura McCrystal.