The late December attack on an outdoor market in Berlin underscores one of the reasons why Donald J. Trump’s virulently anti-refugee rhetoric resonated with so many voters. It also offers an opportunity to examine the inner workings of halachah, Jewish law.

Anis Amri, the perpetrator of the Berlin attack, was an asylum-seeker from Tunisia. He left Tunisia after the success of the January 2011 “Jasmine Revolution” and headed for Italy. There, he and several friends torched a migrant center in Sicily. He was caught, convicted, and sentenced to four years in prison. While in prison, he was transferred six times because of his violent behavior, and because of his penchant for fomenting prison revolts.

When it came time to decide whether to grant Amri asylum, the Italians sought to deport him, but Tunisia said it did not want him back.

In 2015, therefore, Amri went to Germany. He applied for asylum this past April, and was turned down In June, because German intelligence had credible information that he had become radicalized there, and posed an imminent danger. Incredibly, though, he was allowed to roam free because he had no travel documents at the time, and Tunisia was slow in responding to a request for a passport. It arrived on the same day Germany launched an international manhunt for him.

This is the kind of situation Trump railed about on the campaign trail, and has repeated several times since election day. This is especially true of the influx of refugees from Syria and other Muslim nations. “This is going to be potentially a catastrophe for our country,” Trump said at one point about the Syrians. “It’s from within, it could be the all-time great Trojan Horse.”

Trump first used the “Trojan Horse” reference following the November 2015 terror attacks in Paris. He has used it many times since. The Berlin attack only adds weight to his position.

That brings us to Jewish law. In this case, if Jewish law was the governing law, two competing sets of laws would be at work. A decision would have to be made about which one is operative.

The first set of laws has to do with how we deal with strangers in our midst. Says Leviticus 19:33-34: “When a stranger resides with you in your land, you shall not wrong him. The stranger who resides with you shall be to you as one of your citizens; you shall love him as yourself, for you were strangers in the land of Egypt.”

That there should be “one law” for residents and aliens is found in several places, such as Exodus 12:49, Numbers 9:14, and Numbers 15:15.

Possibly, Deuteronomy 23:16-17 offers a very telling law of its own: “You shall not turn over to his master a slave who seeks refuge with you from his master. He shall live with you in any place he may choose among the settlements in your midst, wherever he pleases; you must not ill-treat him.”

The verse refers to a runaway slave, but an argument can be made that a person fleeing from a tyrannical regime given to torture and other forms of persecution falls under the banner of a runaway slave.

It is hard to argue, then, that doors should be closed to such a person.

That Leviticus 19:34 gives as the reason for its law “for you were strangers in the land of Egypt” also has wider implications, because it is saying we must take our own history into account in deciding how we deal with others. Too often in Jewish history, we were forced from one land after another, often unable to find refuge anywhere else. How could we, who were stateless refugees ourselves, deny refuge to other stateless refugees?

Then again, there were nations that did give Jews refuge — some Muslim countries, for example, after the expulsion from Spain in 1492. An updated version of the Leviticus verse could end with “for you were strangers in the land of Morocco,” for example.

There are other laws, however, that also must be considered. Uppermost is Exodus 22:1-2: “If a thief is seized while tunneling, and he is beaten to death, there is no bloodguilt in his case. If the sun has risen on him, there is bloodguilt in that case.”

This law was given at a time when there was no electricity. The words are sparse, but what they say is this: If someone broke into a home in the dead of night and the homeowner killed the intruder, the homeowner is not guilty of a crime because he could not know if the intruder had a weapon and was prepared to kill. If the intruder broke in during the daytime, however, killing him is a crime, assuming that it was clear that he had no weapon.

The bottom line of this law is that if someone is out to kill you and there is no other way to stop him, he can be killed before he kills you, if that is the only way to stop him. By extension, if you are reasonably certain someone has murderous intent, keep him far away from you.

A would-be terrorist disguised as a fleeing refugee fails to qualify here. If it is not possible to determine who is a terrorist and who is a refugee, better to keep refugees far away from you.

To determine which set of laws to follow, we must consider Leviticus 18:5. “You shall keep My laws and My rules, by the pursuit of which man shall live.” The Talmud adds, “but not die by them” (see the Babylonian Talmud tractate Sanhedrin 74a, for example, or the Mishnah in BT Makkot 23b). In other words, if life is threatened, protecting that life trumps almost everything else.

Protecting the stranger and giving him refuge could violate this principle.

Deciding which set of laws to follow is not a question that is easily answered. The decision would depend on how great the threat really is, if that could be determined with a reasonable degree of certainty.