President Recep Tayyip Erdogan, who was in Russia for talks with Vladimir Putin, immediately condemned what he called a "heinous terrorist attack" at state-run Turkish Aerospace Industries (TAI).
"The terrorist attack against TAI, one of the leading lights of the Turkish defence industry, is a vile attack targeting the survival of our country," he said on X.
Interior Minister Ali Yerlikaya said three of the injured were in critical condition and that two attackers, "a woman and a man", had been "neutralised".
Work was under way to determine their identities, he added, without saying whether there were any other attackers still at large.
Footage immediately after the attack, which struck around 3:30 pm (1230 GMT), showed huge clouds of smoke and a large fire raging at the site in Kahramankazan, a small town 40 kilometres (25 miles) north of Ankara.
There was no immediate claim for the attack but the justice minister said an investigation had been opened.
An unconfirmed report by private TV channel NTV said a "group of terrorists" had burst into the building, one of whom "blew himself up" while other media outlets spoke of exchanges of fire that lasted for over an hour.
Haberturk TV said there was an ongoing "hostage situation", with another media pundit later saying "a number of hostages" had been rescued.
There was no immediate comment from the Turkish authorities who quickly moved to impose a blackout of live images from the scene.
Sabah newspaper published what it said was a CCTV image from the entrance showing a black-clad young man with a moustache carrying a rucksack and what appeared to be an assault rifle.
Officials had initially given a toll of three dead but later raised it to four. Haberturk said the last victim was a taxi driver, killed by the attackers who then stole his vehicle.
As night fell, dozens of ambulances could be seen waiting in convoy near the site, their blue lights flashing.
One of Turkey's top defence firms and a major arms producer, TAI employs 15,500 people and has a vast production site covering an area of five million square metres, its website says.
The attack drew condemnation from across Turkey and beyond, with Putin offering Erdogan his "condolences in connection with the terror attack" at the start of their meeting.
The pair were meeting in the Russian city of Kazan on the sidelines of the BRICS summit of major emerging market nations which groups Brazil, Russia, India, China and South Africa.
NATO chief Mark Rutte also offered support to member state Turkey in a call with Erdogan in which he said the alliance "stands with Turkiye," he wrote on X, using the country's official Turkish name.
Statements of condemnation and condolences to the families of the victims were also issued by Brussels, Berlin and the US and French embassies in Turkey.
Back home, Turkish opposition leader Ozgur Ozel who heads the CHP party released a statement condemning the attack and saying he "condemns terrorism, no matter who or where it comes from".
The main pro-Kurdish DEM party also condemned the attack, saying it was "noteworthy that the attack took place just as Turkish society was talking about a solution and the possibility of dialogue" with Kurdish PKK militants.
The leader of the far-right MHP, which belongs to Erdogan's ruling coalition, has invited jailed PKK leader Abdullah Ocalan to address parliament to announce his movement's dissolution.
The PKK has waged an insurgency against the Turkish state since 1984, claiming tens of thousands of lives, with Ocalan held in solitary confinement on a prison island since 1999.
Famed for its Bayraktar drones, Turkey's defence sector accounts for some 80 percent of the nation's export revenues.
The last such attack in Turkey was in January when gunmen opened fire inside a Catholic church in Istanbul, leaving one dead in an assault claimed by the Daish.