PARIS — A police captain was fatally stabbed and his companion was also killed at their home in a small town northwest of Paris on Monday evening, and within hours the Islamic State claimed responsibility for the murders.

The police captain, who was not otherwise identified, was outside his home in Magnanville when he was stabbed by an unidentified assailant, who appeared to have then entered the house and took the captain’s companion and 3-year-old son hostage, according to a statement on the website of the French Interior Ministry and a statement from President François Hollande.

Members of an elite French police unit arrived and raided the home. They fatally shot the attacker, found the woman dead and rescued the boy. The statement added that the woman was an employee of the Interior Ministry.