GONTOR, Indonesia — The silhouette of the large mosque, brick-like but for a bulbous dome, looked blurry in the downpour. The rain of East Java is heavy, lending a sparkle to the green paddies and the scent of moist earth to the air. As the evening prayer ended, hundreds of boys rushed out of the building in waves, mats slung over their shoulders, sarongs hitched up to their knees, flip-flops squelching in the wet.

These students attend Pondok Modern Darussalam Gontor, one of Indonesia’s many Islamic boarding schools, or pesantren. (Estimates range from about 13,000 to 30,000.) Almost three-quarters of the schools, including Gontor, teach secular subjects like science and history in addition to classical Islamic texts and vocational courses in agriculture and mechanics.

Pesantren have existed for centuries in Indonesia, which is home to the world’s largest Muslim population. But their reputation has taken a battering in recent decades, thanks to a wave of terrorist attacks, including bombings in Bali in 2002 that killed over 200 people. By December 2014, militias in Syria and Iraq, including the radical Sunni Islamist group that calls itself the Islamic State, had attracted some 100 recruits from Indonesia, according to the country’s counterterrorism force.

Some pesantren are indeed linked to terrorist groups. The most notorious is the Al Mukmin school in Ngruki, a short drive from Gontor, some of whose graduates have been associated with the Jemaah Islamiyah, the organization responsible for the Bali bombings. Yet Sidney Jones, director of the Jakarta-based Institute for Policy Analysis of Conflict (I.P.A.C.) and a leading authority on terrorist movements in Southeast Asia, estimates that only around 40 pesantren have terrorist connections. Another 200 or so emphasize an orthodox Wahhabi philosophy but do not preach violence.