A soldier patrolling at the famed Louvre museum in Paris shot and seriously injured a machete-wielding man who yelled “Allahu Akbar!” – “God is great!” – Friday in what was described as a terrorist attack.

The assailant, who was carrying two machetes, whipped one out in the underground Carousel du Louvre shopping complex after four soldiers barred him from entering with two backpacks, authorities said.

“That’s when he got the knife out and that’s when he tried to stab the soldier,” police official Yves Lefebvre said.

The soldiers first tried to fight the unidentified man off before opening fire, said Benoit Brulon, a spokesman for the military force that patrols Paris and its tourist attractions. He was shot five times and listed in serious condition.

“The man is on the ground and is not moving,” a police source told Le Parisien newspaper.

The backpacks contained no explosives, police Chief Michel Cadot said.

President Francois Hollande praised the soldiers – one of whom suffered a minor scalp wound – for their “courage and determination.”

“We are dealing with an attack from an individual who was clearly aggressive and represented a direct threat, and whose comments lead us to believe that he wished to carry out a terrorist incident.,” Cadot said, The Guardian of the UK reported.

Prime Minister Bernard Cazeneuve called the attack “terrorist in nature,” Agence France-Presse reported.

A second person was detained but there did not appear to be a link between that person and the attack,” Interior Ministry spokesman Pierre-Henry Brandet said.

An anti-terrorism inquiry has been opened, the public prosecutor said in a statement, Reuters reported.

President Trump fired off a tweet is response to the attack.

“A new radical Islamic terrorist has just attacked in Louvre Museum in Paris. Tourists were locked down. France on edge again. GET SMART U.S.,” he wrote.

Olivier Majewski was just leaving his scooter in the parking lot beneath the Louvre when he saw about 30 or 40 people running and screaming, “There’s been a terror attack!”

The 53-year-old, who hid for about 15 minutes before making his way upstairs, said people were “panicked.”

Hector Clark, a visiting Londoner, was locked inside the Louvre along with other tourists.

“It was intense and everyone was scared at first because the situation was unclear, but people settled down after we heard from the head of security that it was safe,” he told The Local.

The attack at the Louvre — home of Leonardo da Vinci’s world-famous “Mona Lisa” — sparked fresh jitters in a country beset by tourism woes and still reeling from a series of terror attacks that have left it under a state of emergency since November 2015.

The attack’s timing was poor for the City of Light, which planned to submit its official bid to host the 2024 Olympic Games on Friday with a launch show at the Eiffel Tower. It is competing against Los Angeles and Budapest.

Speaking outside the Louvre, Mayor Anne Hidalgo said terrorism threatens all of the world’s big cities and “there is not a single one escaping that menace.”

The incident also came three months before presidential and parliamentary elections that had been forecast to confirm the country’s shift right after five years under Socialist rule.

Some witnesses described scenes of panicked people fleeing after learning about the attack via loudspeaker.

Olivier Majewski was just leaving his scooter in a parking when he saw about 30 or 40 people running and screaming, “There’s been a terror attack!”

The 53-year-old, who he hid for about 15 minutes before making his way upstairs, said people were “panicked.”

Hector Clark, a visiting Londoner, was locked inside the Louvre along with other tourists.

“It was intense and everyone was scared at first because the situation was unclear but people settled down after we heard from the head of security that it was safe,” he told The Local.

Restaurant worker Sanae Hadraoui, 32, was waiting for breakfast at the Louvre’s restaurant complex when she heard gunshots.

“I hear a shot. Then a second shot. Then maybe two more. I hear people screaming, ‘Evacuate! Evacuate!’” she said. “They told us to evacuate. I told my colleagues at the McDonald’s. We went downstairs and then took the emergency exit.”

About 1,250 visitors were kept inside the museum for a while before being ushered out.

“There were announcements, then the security guards started running all over the place and after a short period they started gathering everybody up and getting them to one side of the building,” Albany resident Lance Manus, 73, told Reuters.

“They pulled the shades, they didn’t want anybody to sit by the windows,” said Manus, who was visiting Paris with his wife, Wendy, to mark

their 50th wedding anniversary. “I guess they were concerned that something would be coming from outside.”

A few children cried during the frantic moments, the couple said.

“The very young children, the teachers kept them busy playing games,” said Wendy Manus. “They were singing and trying to keep the children calm and quiet.”

Asked if they had been scared, Lance Manus said: “We come from the US — we have our scares just like you have.”

The soldiers had been taking part in Operation Sentenelle, foot patrols around French landmarks that have been in place since the deadly January 2015 attack on the magazine Charlie Hebdo and a kosher supermarket.

Jihadist gunmen slaughtered 17 people in three days of bloodshed in retaliation for publishing cartoons of the Prophet Mohammed.

On Nov. 13 that year, ISIS jihadists attacked bars, restaurants, a concert hall and the national stadium in Paris, killing 130 people.

In Jan. 7, 2016, a Tunisian man brandishing a butcher knife assaulted cops in front of a police station.

Six months later, another Tunisian extremist rammed a truck through crowds celebrating Bastille Day in Nice on France’s south coast, crushing 86 people to death.

And in November, French police broke up an alleged jihadist terror ring that was believed to be planning to attack Paris.

The Louvre was already suffering from a fall in visitor numbers in the wake of the terror attacks. Last year, numbers dropped 15 percent from 2015 to about 7.3 million, the Guardian reported.

With Post wires