CANBERRA, Australia — A former Australian government minister was branded “stupid” by the prime minister on Friday for visiting the Iraqi front line in a battle between the Islamic State movement and Kurdish Peshmerga.

Wyatt Roy became the youngest-ever Australian federal lawmaker when he was voted into Parliament in 2010 at the age of 20. He was assistant minister for innovation when he lost his seat in elections in July.

Australia’s Special Broadcasting Service on Thursday showed video provided by Roy from Erbil, the capital of Iraqi Kurdistan.

The video showed Roy crouching to avoid gunfire at a Peshmerga position at Domez near the town of Sinjar west of Mosul a week ago as it was attacked by Islamic State fighters.

“Fifteen Daesh soldiers attacked the position that we were at for about half an hour,” Roy said from Erbil, using the Arabic acronym for the Islamic State group.

Prime Minister Malcolm Turnbull said he would give Roy, a staunch political ally, “some very sage and stern advice” when they next met.

“It was very stupid and I’m disappointed in Wyatt,” Turnbull told Radio 3AW. “His actions were very foolish.”

Turnbull said he would not speculate on whether Roy had broken an Australian law. It is an offense to support terrorist groups including the Kurdistan Workers’ Party which is active in northern Iraq and to set foot in Mosul, which is held by Islamic State forces.

Roy said he and British political consultant Samuel Coates could not flee the Peshmerga outpost because of the danger of machine gun bullets, rocket propelled grenades and mortars. Five Islamic State soldiers died.

“Once they (Peshmerga) had pushed them back, they were very adamant that we get in the car and drive as fast as we could in the other direction so I drove us as fast as we could to the town of Sinjar,” he said.

Foreign Minister Julie Bishop said Roy did not ask for Australian government help to travel to Iraq.

“It is irresponsible of Wyatt Roy to travel to the front line of the conflict,” she said in a statement.

Opposition foreign affairs spokeswoman Penny Wong described Roy’s travel as “very unwise and dangerous.”

SBS said Roy was on a flight out of Iraq.

He wrote in The Australian newspaper on Friday that he had been at the Peshmerga outpost for no more than a minute when it came under attack.

“The advantage of doing an unofficial trip is the low profile __ instead of getting whisked around on a whistle stop tour, you can really take the time to get out on the ground,” he wrote.