ISLAMABAD, Pakistan — Militants stormed a court complex in northwestern Pakistan on Monday, killing 4 people and wounding at least 30 people, including a judge, in the latest assault on government authority in the region.

The attack at the court complex in Peshawar, the regional capital, triggered a fierce gun battle with the security forces during which the militants briefly held hostages, according to the provincial information minister, Mian Iftikhar Hussain.

The militants may have been seeking to free fellow extremists who were being held on the court complex, Mr. Hussain said.

The police shot dead one suicide bomber at the court gates before he could detonate his vest, said Jawed Marwat, a senior city official.