Between the devil and the deep blue sea
Here devil is nautical slang for a seam between planks that was difficult to caulk, i.e. make watertight by hammering oakum (fibers of rope) into the gap and then adding tar. The word was particularly used for the long seam of the first plank on the outer hull next to the keel, and for the seam along the edge of the deck where only the thickness of the hull was between this devil and the sea. No doubt awkward and difficult seams were given this name because they were 'the devil' to get at. The whole phrase therefore meant, literally, a physical position between two unpleasant things and, metaphorically, a dilemma.