According to the Mishna (daf 90a), aside from the categories of people who have no share in the World-to-Come and the three kings who have lost their portion, there are four hedyotot – ordinary people – whose activities will keep them from attaining this ultimate reward. The first of these people is Bilam, prophet to the nations, who was hired by King Balak of Mo’av to curse the Jewish people (see Bamidbar Chapter 22).
According to the story in Sefer Bamidbar (see Chapter 23), three times Bilam asked King Balak to bring 14 sacrifices – seven bulls and seven rams – in order to appease God and allow Bilam to curse the Children of Israel. In each of these cases, the sacrifices did not succeed and the prophetic words uttered by Bilam were blessings rather than curses.
Were Balak’s sacrifices totally unsuccessful?
Rav Yehuda quotes Rav as saying that unbeknownst to Balak, these sacrifices served a very important purpose, so much so that we learn from them a general principle – mi-tokh she-lo lishmah, ba lishmah – that a person should always involve himself in Torah and mitzvot, even without the proper intent, since performing those activities – even without proper intent – will, eventually, bring him to proper intent. In fact, the reward for bringing these sacrifices was the eventual birth of a descendant – Rut HaMoaviyah – who would marry into a Jewish family and produce the line that would become the Davidic dynasty (see Megillat Rut).
Although Balak’s intentions were certainly negative ones, the commentaries note that the idea of mi-tokh she-lo lishmah, ba lishmah should not be understood as encouraging negative behavior. Thus, we encourage everyone to learn Torah, even if their intention is not pure, but were someone to desire to study Torah in order to disprove or belittle it, we would not allow him to do so.