The East African victim was left seriously wounded after being shot in Wächtersbach, near Frankfurt in the state of Hesse, after being fired at from a vehicle on Monday afternoon.
The victim is said to be in a stable condition after emergency surgery on his stomach.
“He became a victim because of his skin colour,” public prosecutor Alexander Badle said at a press conference.
The shooting “had a very clear xenophobic motive,” he said, adding however, that “there is no reliable evidence that contact existed… with far-right extremist” groups.
While searching for the perpetrator, police said they later found a 55-year-old German man “apparently lifeless” in a vehicle in a neighbouring town. He was later confirmed dead in hospital.
Investigators believe the suspect, who had no previous convictions, killed himself.
“According to current information, it is likely that this person is the suspected shooter,” police said, adding that his death was not caused by their officers.
Police found five weapons, all legally registered, during a search of the home and car of the suspect, who had recently also sold a sixth gun.
“Why he legally had such an arsenal of weapons, I cannot give any information about”, said Badle.
A letter was also found, but the prosecutor gave no details.