Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

MAINZ, Germany — A Syrian refugee set a shelter for migrants where he was living ablaze and tried to frame neo-Nazis by painting swastikas on its walls, according to authorities in Germany.

The 26-year-old alleged arsonist was dissatisfied with overcrowded conditions at the center, investigators in the western city of Bingen said.

A swastika was sprayed on the basement entrance of a shelter for refugees and migrants in Bingen, Germany, that was set ablaze on Thursday. Frank Rumpenhorst / dpa via AP

"During police questioning, the man admitted that he had set fire in the cellar of the multi-use building,” police spokesman Achim Hansen told NBC News, adding that the Syrian suspect had also stated that “he had a lack of hope for the future."

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

A total of 26 people were in the building when the fire was intentionally started on Thursday. Two firefighters and four residents suffered minor injuries during the incident. The shelter house refugees as well as migrant workers from other European countries.

“This was very close to a catastrophe,” Hansen said, adding that a “very fast response” by the local fire department helped to prevent fatalities.

The arsonist sprayed three swastikas on the exterior of the building in a bid to point police in the direction of far-right protesters. Germany has experienced a recent surge in attacks on refugees and fires at shelters housing migrants.

Related: Gangs Armed With Baseball Bats Hunt Syrian Refugees

More than 1 million asylum-seekers reached Germany during 2015. At times more than 10,000 refugees and migrants arrived daily in the country with a population of around 81 million. Some worry whether Germany can cope with the high number of new arrivals.

The anti-immigration Pegida movement started before the recent influx of people from abroad arrived but has increased its campaigning in recent months.

Meanwhile, police in the northern city of Winsen arrested a 17-year-old Afghan on Sunday after he was allegedly seen setting a fire in the dormitory of another shelter for migrants. All 24 residents were evacuated safely after more than 200 rescue workers were sent.

The motive was not immediately clear.

"The suspect will be brought before a judge [Monday] afternoon,” police spokesman Jan Krueger told NBC News.