The countries state that an attack on one of them should be considered as an "attack on both".
In a statement, it says that the agreement will "develop aspects of defense cooperation between the two countries and strengthen the joint deterrence against all forms of aggression”.
The message comes just over a week after Israel carried out an attack on a residential area in Saudi Arabia's neighboring country Qatar. In May, fighting broke out between Pakistan and India, which included rocket attacks and artillery fire.
The agreement was signed by Saudi Arabia's Crown Prince Mohammed bin Salman and Pakistan's Prime Minister Shehbaz Sharif on Wednesday.