Preheat the oven to 350 degrees F.
In a small saucepan, cook the sugar over medium heat until it starts to melt. Lower the heat and cook until caramelized to a golden brown. (Do not stir or touch the sugar, but swirl the pan to melt evenly.)
Pour into a metal flan mold or 9-inch cake pan. Turn the dish and swirl to evenly coat the bottom. Let caramel cool and harden.
Place the dish in a larger roasting pan and add hot water to come halfway up the sides of the baking dish. In a large bowl, whisk the eggs. Add the condensed and evaporated milks, coffee liqueur, and espresso powder. Whisk well to blend. Pour into the prepared pan. Bake until set and just firm in the center but still jiggles slightly, 50 minutes to 1 hour. Let cool on a wire rack. Refrigerate until well chilled, at least 2 hours.
To serve, run a thin sharp knife around the rim of the flan. Place a platter or large plate on top of the flan and gently flip over so the plate is on the bottom. Lift away the mold. Garnish with cocoa powder and top with chocolate shavings. Cut into wedges and serve immediately.