It is the latest in a series of deadly knife attacks to have shaken Germany in recent months, fuelling concerns over public safety.
The stabbings happened in a public park in the centre of the Bavarian city of Aschaffenburg at around 11.45am, local time, police said.
The attacker targeted a group of children from a daycare centre who were in the park, according to German media.
“Two people were fatally injured,” police said, while another two were seriously hurt and receiving treatment in hospital.
The suspect, a 28-year-old man from Afghanistan, was arrested “in the immediate vicinity of the crime scene”, police added, without indicating a motive.
German media reported that the man was said to have had psychological issues for which he had received treatment. The suspect lived in an asylum centre in the area, news outlet Der Spiegel reported.