The 29-year-old unnamed woman allegedly attacked two women in a department store in the southern city of Lugano.
She has been charged with attempted murder and violating laws against association with Al-Qaeda, IS and related groups, according to the indictment.
She was also charged with unlawful prostitution.
The attorney general’s office said the indictment related to a “jihadist knife attack” and the alleged assailant, a Swiss citizen, “intended to kill her victims and to commit a terrorist act on behalf of IS.”
“The suspect acted wilfully and with particular ruthlessness. She brutally attacked her randomly-selected victims with a knife, with the aim of killing them and thereby spreading terror throughout the population on behalf of the ‘Islamic State’,” it said.
One of the two victims sustained serious neck injuries while the second victim, with help from others at the scene, managed to overpower her attacker and hold her until police arrived.
The attacker was arrested and detained. Police quickly discovered she had been linked to a 2017 jihadism investigation.
The woman had formed a relationship on social media with a jihadist fighter in Syria and attempted to travel to the war-torn country to meet him, police alleged at the time.
She was stopped by Turkish authorities at the Syrian border and sent back to Switzerland, they said, adding that the woman had suffered from mental health problems and been admitted to a psychiatric clinic.