Pakistani security forces have exchanged gunfire with hundreds of separatist militants as they sought to free about 300 hostages aboard a train in the country’s rugged southwest, officials said.