Officials and his son said the far-right candidate was in stable condition, though the son also said Bolsonaro suffered severe blood loss and arrived to the hospital "almost dead."
Numerous videos on social media showed Bolsonaro, who has promised to crack down on crime in Latin America's largest nation, being stabbed with a knife to the lower part of his stomach. At the moment of the attack, Bolsonaro was on the shoulders of a supporter, looking out at the crowd and giving a thumbs up with his left hand.
After the attack, he is seen flinching and then goes out of view. Other videos show supporters carrying him to a car and hitting a man who was apparently the attacker.
Police spokesman Flavio Santiago confirmed to The Associated Press that his attacker had been arrested.
Bolsonaro was taken to a hospital in the city he was campaigning, Juiz de Fora, about 125 miles (200 kilometers) north of Rio de Janeiro, and was in good condition, Santiago said.
Santiago said the attacker was identified as Adelio Bispo de Oliveira. He said the suspect was beaten badly by Bolsonaro supporters after the attack. The man was arrested in 2013 for another assault, police said.
Luis Boudens, president of the National Federation of Federal Police, told the AP that the assailant appeared to be deranged.
"Our agents there said the attacker was 'on a mission from God,'" Boudens said. "Their impression is that they were not dealing with a mentally stable person. He didn't expect to be arrested so quickly, agents reacted in seconds."
In a statement, the hospital said Bolsonaro was in surgery but did not elaborate.
Bolsonaro's son, Flavio Bolsonaro, initially posted on Twitter that the injury was superficial and his father was fine. However, an hour later he posted another tweet saying the wound was "worse than we thought."
Flavio said the puncture had hit parts of his father's liver, lung and intestines and he lost a lot of blood.
He arrived at the hospital "almost dead," Flavio wrote. "His condition now seems stabilized. Please pray."
A statement from federal police said the candidate had bodyguards. In the videos, Bolsonaro does not appear to be wearing a protective vest. Such measures are rare for candidates in Brazil.
"This episode is sad," President Michel Temer told reporters in Brasilia. "We won't have a rule of law if we have intolerance."
Bolsonaro, a former army captain, is second in the polls to jailed ex-President Luiz Inacio Lula da Silva, who has been barred from running but continues to appeal.
Despite being a congressman since 1991, Bolsonaro is running as an outsider ready to upend the establishment by cracking down on corruption in politics and reducing crime, in part by giving police a more free hand to shoot and kill while on duty.
While Bolsonaro has a strong following, he is also a deeply polarizing figure. He has been fined, and even faced charges, for derogatory statements toward women, blacks and gays.
He speaks nostalgically about the country's 1964-1985 military dictatorship and has promised to fill his government with current and former military leaders. His vice presidential running mate is a retired general.
Earlier this week, Bolsonaro said during a campaign event that he would like to shoot corrupt members of the leftist Workers' Party, which made da Silva its candidate. The comment prompted an immediate rebuke from the attorney general, who asked Bolsonaro to explain that comment.
In a sign of how polarized Brazilian politics has become, people took to Twitter Thursday night to either to decry the stabbing and ask for prayers for Bolsonaro or to say that the candidate had brought it upon himself and even may have staged it.
The top five trending topics in Brazil were related to the stabbing, and someone even created an account for the knife, whose tweets had been retweeted thousands of times just hours after the attack.
Other presidential candidates quickly denounced the stabbing.
"Politics is done through dialogue and by convincing, never with hate," tweeted Gerado Alckmin, former governor of Sao Paulo who has focused negative ads on Bolsonaro.
Fernando Haddad, who is expected to take da Silva's place on the Workers' Party ticket, called the attack "absurd and regrettable."
The attack comes at a time of increasingly heated rhetoric, and violence, related to campaigns and candidates.
In March, while da Silva was on a campaign tour in southern Brazil before his imprisonment, gunshots hit buses in his caravan. No one was hurt, and da Silva, who is in jail on a corruption conviction, was not in the vehicles that were hit.
Also in March, Marielle Franco, a black councilwoman in Rio de Janeiro, was shot and killed along with her driver after attending an event on empowering black women.
It wasn't immediately clear how the attack on Bolsonaro might reshape a presidential race very much up in the air with the front-runner, da Silva, in jail. In many ways, the incident feeds Bolsonaro's narrative that Brazil is in chaos and needs a strong hand to steady it.
"It's likely that Bolsonaro will use the attack to argue his opponents are desperate, that they had no other way to stop him," said Mauricio Santoro, a political science professor at Rio de Janeiro's state university.