JAKARTA, Indonesia — A married couple who appear to have been inspired by the Islamic State attacked Indonesia’s chief security minister, Wiranto, as he visited western Java on Thursday, the police said.

Mr. Wiranto, 72, a former general who like many Indonesians uses one name, suffered two stab wounds to his stomach, said the national police spokesman, Dedi Prasetyo.

“It was very quick and spontaneous,” he said.

Mr. Wiranto was taken by helicopter to a hospital in Jakarta, the capital, where he underwent surgery and was said to be in stable condition.

The head of Indonesia’s intelligence agency, Budi Gunawan, told reporters that the two assailants were members of an Islamist terror group, Jamaah Ansharut Daulah, that has pledged loyalty to the Islamic State and has been responsible for several recent attacks in Indonesia.