▁inc urs ions ▁and ▁a ▁Portuguese ▁invasion ▁at ▁the ▁battle ▁of ▁K s ar ▁el ▁K eb ir ▁in ▁ 1 5 7 8 . ▁The ▁reign ▁of ▁A hm ad ▁al - M ans ur ▁brought ▁new ▁wealth ▁and ▁prest ige ▁to ▁the ▁Sultan ate , ▁and ▁a ▁large ▁expedition ▁to ▁West ▁Africa ▁inf lic ted ▁a ▁cr ushing ▁defeat ▁on ▁the ▁Song h ay ▁Empire ▁in ▁ 1 5 9 1 . ▁However , ▁man aging ▁the ▁territ ories ▁across ▁the ▁Sah ara ▁proved ▁too ▁difficult . ▁After ▁the ▁death ▁of ▁al - M ans ur , ▁the ▁country ▁was ▁divided ▁among ▁his ▁sons . ▁ ▁In ▁ 1 6 3 1 , ▁Mor oc co ▁was ▁reun ited ▁by ▁the ▁A la ou ite ▁dynast y , ▁who ▁have ▁been ▁the ▁r uling ▁house ▁of ▁Mor oc co ▁ever ▁since . ▁Mor oc co ▁was ▁facing ▁ag gression ▁from ▁Spain ▁and ▁the ▁Ott oman ▁Empire ▁al lies ▁pressing ▁west ward . ▁The ▁A la ou ites ▁succeeded ▁in ▁stabil ising ▁their ▁position , ▁and ▁while ▁the ▁kingdom ▁was ▁smaller ▁than ▁previous ▁ones ▁in ▁the ▁region , ▁it ▁remained ▁quite ▁wealth y . ▁Again st ▁the ▁opposition ▁of ▁local ▁tribes ▁Is mail ▁I bn ▁Sh ar if ▁( 1 6 7 2 – 1 7 2 7 ) ▁began ▁to ▁create ▁a ▁un ified ▁state . ▁With ▁his ▁Jay sh ▁d ' A hl ▁al - R if ▁( the ▁R iff ian ▁Army ) ▁he ▁seized ▁Tang ier ▁from ▁the