Police in Parchim, Mecklenburg-Western Pomerania, said that the two had somehow gained access to the area around the building and that one of them had been carrying a 20.5-centimetre knife.
Refugees housed in the block who were standing outside spotted the men before they were able to get close.
They fled to safety and informed security guards, who called the police.
Although both men tried to escape, they were quickly caught by officers and taken into custody. Tests showed that both men had more than two parts per thousand of alcohol in their bloodstream – more than six times the legal limit for driving.
Police said that both men made xenophobic comments while their blood was being taken.
The men are now under investigation for crimes against weapons laws and breach of the peace.
Arson attack in Leipzig
Also on Tuesday night, an unknown attacker set a fire in a building that was scheduled to be used as refugee accommodation in Leipzig, Focus reported.
A witness called firefighters immediately, who were able to stop serious damage to the structure, police said early on Wednesday.
A group of 56 refugees had been scheduled to move in on Wednesday.
Police have so far found no trace of the culprit.