Today the expression "devil to pay" is used primarily to describe having an unpleasant result from some action that has been taken, as in someone has done something they shouldn't have and, as a result, "there will be the devil to pay." Originally, this expression described one of the unpleasant tasks aboard a wooden ship.
The "devil" was the wooden ship's longest seam in the hull. Caulking was done with "pay" or pitch (a kind of tar). The task of "paying the devil" (caulking the longest seam) by squatting in the bilges was despised by every seaman.