The operation Wednesday was necessary because of a blockage of the small intestine, Albert Einstein Hospital in Sao Paulo said, adding that the procedure was successful.
With the much more popular former president Luiz Inacio Lula da Silva in prison and out of the race, Bolsonaro is leading in the polls ahead of the October 7 vote for a new president.
A leftwing assailant stabbed Bolsonaro, 63, last week as he did a campaign walkabout in the town of Juiz de Flora in southeastern Minas Gerais state.
After the attack, he first underwent a colostomy.
Bolsonaro’s son Flavio said the latest surgery went well.
“My father is paying a very high price for wanting to save Brazil. He is literally giving his blood,” the son, a state lawmaker who is running for a seat in the federal senate, wrote on Twitter.
Bolsonaro is ahead with a 24 per cent share among people who say they will vote, far ahead of the next strongest candidate, Ciro Gomes of the centre-left with 13 per cent, according to a Datafolha poll released Monday.
Bolsonaro is a former army captain who has been criticized for remarks deemed misogynist and homophobic and has spoken fondly of the military dictatorship that ruled Brazil from 1964 to 1985.