Decadent Chocolate Cake

For cake:
5 ounces fine-quality unsweetened chocolate, chopped
2 1/4 sticks unsalted butter, softened
2 3/4 cups sifted cake flour (not self-rising; sift before measuring)
1/4 cup unsweetened cocoa powder (not Dutch-process)
2 teaspoons baking soda
1 teaspoon baking powder
1/2 teaspoon salt
4 large eggs, at room temperature 30 minutes
1 cup granulated sugar
1 cup packed light brown sugar
1 1/2 teaspoons pure vanilla extract
2 cups sour cream

For frosting:
1 cup sugar
6 tablespoons all-purpose flour
6 tablespoons unsweetened cocoa powder (not Dutch-process)
1 1/2 cups whole milk
4 ounces fine-quality unsweetened chocolate, finely chopped
1 tablespoon pure vanilla extract
6 sticks (1 1/2 pound) unsalted butter, at room temperature

Cake:
Preheat oven to 350°F with rack in middle. Butter cake pans, then line bottom of each with a round of parchment paper and butter parchment. Flour pans, knocking out excess. Melt chocolate with butter, then cool. Sift together flour, cocoa powder, baking soda, baking powder, and salt. Beat eggs, sugars, and vanilla in a large bowl with an electric mixer at medium speed until pale and thick, 3 to 5 minutes. At low speed, mix in melted chocolate until incorporated, then add flour mixture in 3 batches alternately with sour cream, beginning and ending with flour mixture and mixing until each addition is just incorporated. Spread batter evenly in pans and rap pans several times on counter to eliminate air bubbles. Bake until cakes pull away from sides of pans and a wooden pick inserted in center of each comes out clean, 40 to 50 minutes. Cool in pans on a rack 10 minutes, then run a knife around edges of pans. Invert onto racks and discard parchment, then cool completely, about 1 hour.


Make frosting and assemble cake:
Whisk together sugar, flour, cocoa powder, and a pinch of salt in a small heavy saucepan over medium heat, then add milk and cook, whisking constantly, until mixture boils and is smooth and thick, 3 to 5 minutes. Remove from heat and whisk in chocolate and vanilla until smooth. Transfer to a bowl to cool to room temperature, covering surface with parchment paper to prevent a skin from forming. Beat butter with an electric mixer until creamy, then add cooled chocolate mixture a little at a time, beating until frosting is fluffy and spreadable. Cut each cake horizontally into 2 layers with a long serrated knife. Put 1 layer on a cake stand or large plate and spread top with 1 1/4 cups frosting. Repeat with 2 more layers, then add remaining layer and spread top and side of cake with remaining frosting.