If your context allows for some expressive vulgarity, then you could consider by a gnat's dick. E.g.:
We missed that train by a gnat's dick!
This phrase is not one which is completely fixed, and as such one may encounter varying permutations, including by a gnat's bollock and by a gnat's cock.
Should they even have sex organs (a matter better resolved on another Stack Exchange website), the expression holds that a gnat's penis would be very small indeed, thereby providing a vivid analogue for a minute quantity of space or time.
The phrase is therefore best reserved for situations that a) pertain to very narrow margin of success or failure and b) are informal.