An video circulated on Twitter, published by major Brazillian newspapers, showed the moment when an unidentified individual stabbed the politician in the lower abdomen.
The other presidential candidates were also reportedly quick to denounce the attack. Supporters can then be seen beating up the suspect.
Bolsonaro was recovering in hospital from an injury that was "only superficial", tweeted his son, Flavio, who is himself a candidate for the Brazilian senate.
The news agency said a person was detained.
Flavio said the puncture had hit parts of his father's liver, lung and intestines and he lost a lot of blood. "He lost a lot of blood, arrived at the hospital. nearly dead. He appears to have stabilized now", he said.
He was identified as Adelio Bispo de Oliveira, 40, and said to be a member of the left-leaning PSOL party from 2007 to 20014.
President Michel Temer quickly condemned the attack and instructed his Minister of Security Raul Jungmann to reinforce security for candidates and conduct "a rigorous investigation", a spokesman for the presidency told AFP.
Bolsonaro underwent surgery for multiple wounds his mid-section and was listed in stable condition after the attack during a walkabout in the southeastern city of Juiz de Fora. "In this hard moment that our country is going through, we must rigorously safeguard human life and the defense of our institutions and democratic life", she said.
Bolsonaro has drawn a big following in Brazil for his tough talk on crime and lack of a filter.
However, he has recently gained popularity due to his strong populist and anti-corruption messages that he issued at a time when the Brazilian ruling elites got mired in a multimillion-dollar corruption scandal, involving Brazil's meatpacking and oil giants. Many of his followers refer to him as the "Brazilian Trump", BBC reported.
The former army captain surged in the polls and became the frontrunner with 22 percent of the vote share, just after jailed former president Luiz Inacio Lula da Silva was barred from running. The first round of Brazil's presidential election is October 7.
"This incident increases Bolsonaro's election chances", said Richard Back, head of Latin America political strategy at XP Investimentos.