What does the expression “within an ace of” mean and Where does it come from?

The expression “within an ace of” means about as close as possible; on the very edge of.

At dice, an ace is the lowest number, and ambsace, literally, both aces, from the Old French, “ambes as”, is the lowest possible throw, hence the epitome of bad luck, almost nothing.

Thus, “ambsace” very naturally came to mean an extremely small point; less of a point than would be represented by the pip of a single ace. And, in the same figurative manner, “within ambsace of” measured a degree of closeness that was no more than half a pip or jot.

This latter wording appears to have been the original form of the expression; but, through careless use or faulty hearing, this became corrupted into the only form heard today, “within an ace of,” though both wordings were in use in the seventeenth century.