At least 40 people were killed and dozens injured when a packed Pakistani inter-city train ploughed into another express that had derailed just minutes earlier, officials said.