JERUSALEM — Israel’s Supreme Court ruled on Tuesday that a senior official of the advocacy group Human Rights Watch must leave the country within 20 days, invoking a contentious law that bars entry to foreigners who have publicly called for a boycott of Israel or its settlements in the occupied West Bank.

The ruling upheld a 2018 decision by Israel’s interior minister, Aryeh Deri, itself upheld in April by a lower court, to bar Omar Shakir, an American citizen and the organization’s Israel and Palestine director, from staying and working in the country. The case has shone a spotlight on the limits of what Israel views as legitimate criticism and human rights activity, as well as of its commitment to liberal democratic values.

Rejecting Mr. Shakir’s appeal, the judges wrote that the decision not to renew his visa had stemmed from “a real concern” that Mr. Shakir, through his activities, was “exploiting” his stay to delegitimize Israel and to promote the boycott movement against it.

The judges said that the ruling against Mr. Shakir as an individual had no bearing on the work of other rights advocates and did not mean that Israel was “closing its gates” to other representatives of Human Rights Watch, a prominent New York-based organization, or to similar groups.