Iran's President Hassan Rouhani says Tehran is not interested in maintaining tensions with Saudi Arabia and responded positively when Pakistan tried to mediate between the two rivals.

Speaking at a news conference Saturday to mark the end of his two-day visit to Pakistan, Rouhani said Saudi plays an important role in the Muslim world and that "if there is any problem between two countries, it should be resolved through talks."

Pakistan is a key ally of Saudi Arabia and Iran shares a long border with Pakistan.

The trip was Rouhani's first visit to Pakistan, and followed efforts by Saudi Arabia to court Islamabad to increase its participation in a new Saudi-led military alliance of mostly Sunni nations, a coalition perceived by Tehran as an anti-Shiite block.