The man had rushed towards a group of soldiers and guards in the Carrousel du Louvre, the underground plaza adjoining the museum, according to Paris police chief Michel Cadot. Wielding the weapon, the man shouted "Allahu akbar" (God is greatest), Cadot said.
The soldier fired five shots in response.
The attacker was wearing two backpacks and may have had a second weapon, Cadot said. He was seriously injured by a bullet to the stomach. One solider was slightly injured on the scalp.
No explosives were found in the two backpacks of the man, who was taken into custody alive and conscious. He was tended to by the fire service, Cadot said.
A second person was arrested, the French Interior Ministry said, although it was not immediately clear whether they were connected to the attack.
The French Prime Minister, Bernard Cazeneuve, described the attack as "terrorist in nature". The Paris prosecutor announced a terror investigation.
About 250 visitors who were in the Louvre museum at the time were taken to a secure area and were being evacuated in small groups after checks were carried out.
A security cordon was set up after the incident, which began at 10 a.m. (4 a.m. ET.)
French Interior Minister Bruno Le Roux hailed the police and military for their calm and professionalism in subduing the attacker -- and said the incident was a reminder of the present threat.
The mayor of Paris, Anne Hidalgo, added: "In this context of terrorist threat that concerns every big city in the world, we saw how efficient and relevant Paris security features were."
A music producer from Florida, VoiceB0xx, tweeted that "something is going down" at the Louvre, saying he saw "30 National Police vehicles with guns drawn."
State of emergency
The Louvre, voted the most popular museum in the world in 2016, is home to the Mona Lisa, the Venus de Milo and the Code of Hammurabi, among other famous works.
But since a series of terror attacks have plagued France, visitors to the Parisian institution have fallen.
Last year, 7.3 million people visited the museum, a 15% drop from 2015, according to French news agency AFP.
A state of emergency has been in place across France since the Paris terror attacks in November 2015, in which 130 people were killed and hundreds injured. In January that year, 17 people were killed in attacks on the satirical magazine Charlie Hebdo, a kosher grocery store, and the Paris suburb of Montrouge.
Last July, a radicalized Tunisian plowed a 20-ton truck into crowds on the Promenade des Anglais in Nice during a Bastille Day celebration, killing 86 people and injuring 200 others.
Authorities continue to monitor thousands of suspected Islamist radicals.