Bolsonaro was being led through a crowd on the shoulders of supporters in Juiz de Fora city, in the southern state of Minas Gerais, when an assailant stabbed him from the front. Video shows Bolsonaro grimacing in pain before being carried away.
Police have arrested a suspect, Adelio Bispo de Oliveira, 40, who has been charged in connection with the attack, according to state news agency Agencia Brazil. The suspect's Facebook page featured posts railing against Bolsonaro, Agencia Brazil quoted police as saying.
Known to many of his countrymen as the "Brazilian Trump," Bolsonaro, 63, was taken to a local hospital where medical officials and his family said he was in a stable condition.
The attack on Bolsonaro, notorious for making racist, sexist and homophobic remarks, has further ratcheted up tensions weeks ahead of elections in October.
Bolsonaro, a pro-gun congressman since 1991, has cast himself as a political outsider, a firebrand attracting millions of supporters who believe he can shake-up Brazil's corruption-marred political class.
Recent polls estimate that Bolsonaro is the favorite to win the election with a 10% lead over his nearest rival, former President Luiz Inacio Lula da Silva.
However, doctors at the Santa Casa hospital, where Bolsonaro was taken for surgery, said his wounds may interrupt his campaigning as his recovery may take days or weeks.
Earlier his family thought his wound was superficial, but later they reported that there had been fears for his life.
"Unfortunately it was more serious than we hoped," tweeted his son Flavio Bolsonaro. "The wound reached part of his liver, lung and intestine. He lost a lot of blood, reaching the hospital...almost dead...his condition now seems stable. Please pray!"
His other son, Eduardo Bolsonaro said if the hospital had not been nearby he could have died.