Original: In the last years of the Hafsids, Spain seized many of the coastal cities, but these were recovered by the Ottoman Empire.
Simplified: In the last years of their reign, the Hafsids became weak and Spain took control of many city coasts until they were finally occupied by the Ottoman Empire.