ISLAMABAD—China will build a pipeline to bring natural gas from Iran to Pakistan to help address Pakistan’s acute energy shortage, under a deal to be signed during the Chinese president’s visit to Islamabad this month, Pakistani officials said.

The arrival of President Xi Jinping is expected to showcase China’s commitment to infrastructure development in ally Pakistan, at a time when few other countries are willing to make major investments in the cash-strapped, terrorism-plagued country.

...