Were they actually defeated, because I get the impression Hamilcar was undefeated. Also, was hamilcar part of the mercenary rebellion and if so, how did he manage to survive this and end up still in command of carthaginian forces in Spain?
Adrian Goldsworthy talks about this in his book The Fall of Carthage. TL:DR Both sides were exhausted. Rome and Carthage basically fought each other to a stand still.
Carthage started out the war with a qualitative and quantitative naval advantage, which was helpful since most of the war was fought at sea. The Romans quickly adapted by building a navy, developing the Corvus which made boarding ships a lot easier and allowed the Romans to fight better at sea, and later the Romans learned how to fight naval battles on Carthaginian terms (i.e. maneuver and ramming) and actually won the last naval battle of the war as well as fighting the Carthaginians to a stalemate in Sicily. Rome's victory in the Battle of the Egadi Islands destroyed the Carthaginian fleet and they couldn't afford to build a new one.
Thus in 241 B.C. both sides were at the end of the financial and human resources although Rome still had an intact fleet, unlike Carthage. In fact Carthage was so broke it couldn't pay its mercenaries and suffered a huge revolt of which the Romans took advantage to take the island of Sardinia which was specifically named Carthaginian territory in the treaty ending the war.