Senator Gomes, 56, was driving a digger towards a fence behind which a group of masked military police officers were protesting when he was hit by two bullets in the town of Sobral.
He is in hospital in a stable condition.
For months, members of the military police have been conducting strikes and protests to demand pay increases.
Video shared on social media shows Senator Gomes driving a digger at the metal fence and lifting it up with the digger’s arm while masked policemen gathered behind it shout.
Several shots ring out and the windscreen of the digger and one of its windows shatters.
Photos taken subsequently show Mr Gomes being helped away, his T-shirt showing a large blood stain.
It is not clear who fired the shots.
Members of the military police in Sobral, in the north-eastern state of Ceará, have been demanding better pay since late 2019 and holding strikes.
They argue that they are being paid less than their counterparts elsewhere.
Police officers are banned from going on strike under Brazilian law and a court in Ceará ruled this week that those defying the ban could face prison.
As part of their protest, the officers barred the entrance to a military police station in the town to impede other members of the force who have not joined their strike from working.
Senator Gomes organised a counter-protest and warned the officers to clear the road. He told them over a megaphone that they had five minutes to clear off.
When they did not, he got into the cab of the digger and drove towards the fence behind which they were gathered.
Watch the video below: