Original: However, soon after Panah Ali khan realized that in order to secure himself and his newly-established khanate from external threats, and especially from the invasions from Iran, he needed to build a new more reliable castle.
Simplified: However, soon afterwards Panah Ali khan realized that in order to secure himself and his newly-established khanate from external threats, and especially from the invasions from Iran, he needed to build a new more reliable castle.