The devices in abandoned suitcases on two trains failed to go off. Police said the bombers had intended to kill large numbers of people.
The student had studied in the Baltic Sea port city of Kiel, where he was arrested in the early morning.
Chief prosecutor Monika Harms said he had been in Germany since 2004. Reports say police searched his home in the city on Saturday afternoon.
He is believed to be "one of the two suspects that have been sought since yesterday with the help of video footage that was made public," the public prosecutors' office said.