How you communicate an underestimate will differ slightly if you are a freelancer/consultant compared to an employee. The primary difference being the level of technical sophistication of the person you are telling.
The basics should be the same with either party, though.
Always open the communication lines as soon as you know you are behind. You don't have to say "My project is definitely going to be late" but rather be honest. If you are behind on a milestone, speak up now.
Don't assume you can just make up the time during the rest of the project. The worst thing you can do when your project is running behind is make it a surprise to everyone on the day of the deadline.
When you speak up early, this is also good for everyone else involved in the project. If you are a freelancer, you can work with your client to make adjustments to the scope to keep things on track or they can delay other parts of the project if it is a coordinated effort of more than just your work.
If you are an employee, your manager or team can assess the situation and make plans to make the project successful. This can include changing scope, getting you help from more senior developers, reassigning parts of the project, etc.
There's no shame in this: the ultimate goal is to be part of successful projects not looking like a hero. Plus you look a lot better if you give everyone a chance to come up with a plan rather than just springing it on them at the last minute that you aren't done with your part.
It is also a lot less stressful when your team is working together to work toward a solution. A lot of the stress from this situation is worry about letting the team down or trying to work too much to make up time.
Be prepared for people to ask why you are behind though. Give honest answers. I hope your answer isn't "I underestimated the project so I thought I had a lot more time to surf HN", though.
This means you need to be completely honest with everyone on your team and speak up early so plans can be made. Again, if you wait until the last minute to say something, after you tried working long hours to make up time (and failed), there isn't much that can be done. The project is already late at that point.
This is when you get some real anger directed at you, because you screwed over the team by pretending there wasn't a problem. You also took away the team's ability to make adjustments to compensate and you know.. work as a team.
So really, how you bring up the fact that you underestimated part (or all) of your project isn't really as important as doing it right away. Be honest with everyone about where you stand.
You demonstrate willingness to do this by actually doing it.