I've found the best solution on my end is simply to first try to estimate a little pessimistically, and then to charge enough that I'll feel fine even if the project takes me a couple days longer than I thought. If a totally unexpected pitfall appears, a reasonable client will be open to renegotiating.
It's so worth it just to avoid the not-so-goodwill that seems to accompany hourly billing so often.