When a boxer is suffering a beating and his corner want to stop the fight they literally throw in the towel to indicate their conceding of the fight. It became a figurative phrase around 1916. Read all about it here .
This odd phrase originated in the 1500s in Thomas Murner’s satirical work Narrenbeschwörung (Appeal to Fools). Read all about the intended meaning then and now here .