US Defense Secretary James Mattis was targeted in a rocket attack that left at least five civilians wounded at an Afghan airport Wednesday hours after he arrived to pledge support for the government.

The rockets landed in an open area after being fired at Kabul’s Hamid Karzai International Airport, Interior Ministry spokesman Najib Danish told CNN.

The Taliban claimed responsibility for the attack, which was meant to target Mattis’ plane, Taliban spokesman Zabiullah Mujahid tweeted.

But Mattis and NATO Secretary-General Jens Stoltenberg had already left the airport at the time of the incident, Danish said.

One rocket struck a home near the airport, wounding the five victims, one of whom was a woman who was “not in a good health condition,” Danish added.

Up to 40 rounds of munitions were fired — 29 of which were rocket-propelled grenades — toward a guard tower and hit the south side of the airport, a US military official told CNN.

Tumor Shah Hamedi, director of Kabul airport, said all flights were halted as a result of the attack.

Mattis’ unannounced visit was his first trip to the country since President Trump announced a new Afghan strategy late last month.

At a press conference with Afghan President Ashraf Ghani and Stoltenberg, Mattis said, “An attack on an airport anywhere in the world is a criminal act by a terrorist.”

“If in fact, this is what they have done, they will find the Afghan Security Forces continuing on the offensive against them in every district of the country right now,” he added.

Ghani said at the presidential palace that special forces troops brought the attack under control.

Both Mattis and Stoltenberg have vowed to do everything possible so the country “doesn’t again become a safe haven for international terrorists.”

Stoltenberg said NATO was aware of “the cost of staying in Afghanistan, but the cost of leaving would be even higher.”

He said, “If NATO forces leave too soon, there is a risk that Afghanistan may return to a state of chaos and once again become a safe haven for international terrorism.”

Stoltenberg added that NATO was committed to funding the Afghan security forces until at least 2020, and would continue to provide them almost $1 billion each year.

Mattis, who arrived from India, where he sought support for the US administration’s new South Asia security plan, said Washington supports a negotiated settlement between the Taliban and Afghanistan.

Promising a more “holistic” approach without fixed timetables and involving other countries in the region, he said the Taliban would have to learn they could not defeat the government, Reuters reported.

“I want to reinforce to the Taliban that the only path to peace and political legitimacy for them is through a negotiated settlement,” Mattis said.

“The sooner the Taliban recognizes they cannot win with bombs, the sooner the killing will end,” he said.

Trump has promised a stepped-up military campaign against Taliban insurgents, who have gained ground as they seek to re-establish Islamic law after their 2001 ouster.

There are about 8,400 US troops in Afghanistan as part of the 13,500-strong NATO-led Resolute Support mission advising and training Afghan forces, as well as a separate counterterrorism mission targeting ISIS and al Qaeda.

Mattis has said the United States will send an additional 3,000 troops to help train Afghan security forces.

With Post wires