|President Duterte said he wanted to show solidarity with his soldiers|
The fight has been raging since May when Islamic State-inspired Maute rebels captured parts of the conflict-hit city.
Around 700 people, including many militants, have so far died in the three-month battle.
The President told troops: 'We will not stop until the last terrorist is neutralised'
President Rodrigo Duterte reportedly fired the weapon as he met soldiers during his third Marawi visit.
It is not known if his shots hit Maute gunmen.
The Filipino government released an image of him holding a sniper rifle, along with the caption: "President Rodrigo Duterte fires a shot towards enemy lines during his third visit to the troops of the joint special operations task force trident in war-torn Marawi City."
Troops have been battling insurgents from the Maute group in Marawi City
|The President told troops: 'We will not stop until the last terrorist is neutralised'|
He added: "We will not stop until the last terrorist is neutralised."
Pres. Duterte visits troops in war-torn Marawi for the third time. #DefendRepublic5:41 AM - Aug 25, 20171 35 83 Presidential Comm@PresidentialComHis visit to the city comes after government troops managed to retake the city's mosque, which was thought to be a militant hideout.
The insurgents are thought to be aiming to establish an Islamic State province in the Philippines.
President Duterte has also been battling drug gangs since last year where more than 5,000 suspects have been killed.