The man began attacking a fellow passenger in the Grafing S-Bahn station at around 5am, police said in a statement.
After the first attack on the train, the assailant stabbed another on the platform, then left the station and slashed two more men on bicycles outside, said Bavarian police spokesman Karl-Heinz Segerer on n-tv news channel.
"In the meantime local police received an emergency call, and the officers quickly arrived at the scene and were able to detain the man," said Segerer.
The other injured men were aged 43, 55 and 58.
Photos from the scene showed the bare-footed attacker's bloody footprints on the station platform and bicycles belonging to two of the wounded men lying on the ground.
A helicopter and several ambulances were called to the scene to bring the wounded people to hospital, Munich's Merkur newspaper reported.
Although Grafing station was closed for several hours, trains were once again passing uninterrupted by late morning.
Town mayor Angelika Obermayr expressed shock at the bloody crime in the sleepy town of 13,000 people.
"We are an absolutely peaceful Bavarian small town in the greater Munich region," she said on n-tv.
"Something like this is absolutely new and has deeply shocked the people here who only know things like that from television.
"That something like that happened here is absolutely unbelievable."
Islamist connection unclear
In the early afternoon, Bavarian interior minister Joachim Herrmann said that there was so far no evidence of an Islamist connection behind the attack.
A spokesman for state prosecutors had earlier said that the attacker had "made remarks at the scene of the crime that indicate a political motive - apparently an Islamist motive".
Early eyewitness reports had suggested that the man with the knife had been shouting “Allahu Akbar” – Arabic for “God is great" - broadcaster Bayerische Rundfunk(BR) reported.
Another eyewitness told one local reporter that the aggressor had shouted "you are all unbelievers" in German.
One witness told me: "he shouted you are all infidels!" Using the German word not arab. Kuffar @grafing— sammy khamis (@Sammy_Khamis) 10. Mai 2016
"We are still determining what the exact remarks were," the prosecutors' spokesman told AFP.
Police have scheduled a press conference on the investigation for 3 pm on Tuesday.
A police spokesman said that the assailant was a 27-year-old German not resident in Bavaria.
He is being questioned in the police station at Ebersberg, north of Grafing. Interior minister Herrmann said that his behaviour was “not very co-operative”.
Hermann said the attacker, named locally as Paul H., was a German national, as authorities said he hailed from central Hesse state and did not have a migrant background.
"As to what extent there were other background factors, or whether this is more about questions of mental instability or drug addiction, still needs to be investigated," Hermann said on BR24 television.
Third knife attack in recent months
In the rare German-language video they urged their "brothers and sisters" in Germany and Austria to commit attacks against "unbelievers" at home.
Since then Germany has seen at least two bloody knife assaults blamed on Islamists, before Tuesday's attack.
In February a 15-year-old girl identified as Safia S. stabbed a policeman in the neck with a kitchen knife in what prosecutors later said was an IS-inspired attack.
She attacked the officer during a routine check at Hanover train station in the country's north before being overpowered by another police officer.
Federal prosecutors later said the teenager had "embraced the radical jihadist ideology of the foreign terrorist group Islamic State of Iraq and Syria" and was in contact with an IS fighter in Syria.
Last September a 41-year-old Iraqi man identified as Rafik Y. stabbed and seriously wounded a policewoman in Berlin before another officer shot him dead.
The man had previously spent time in jail for membership of a banned Islamist group and had been convicted in 2008 of planning an attack in Berlin against former Iraqi prime minister Iyad Allawi.