Beat sugar and egg yolks together in a large bowl until creamy.
Mix in cocoa powder, cornstarch, and salt until well blended.
Gently stir in milk.
Pour mixture into a large, heavy-bottomed saucepan. Cook over medium heat, stirring constantly with a wooden spoon, until boiling and thickened enough to coat the back of a metal spoon, 5 to 7 minutes.
Remove from heat; stir in butter and vanilla extract. Set aside to cool slightly.
Pour mixture into prepared pastry shell; chill pie in the refrigerator until set, 2 to 4 hours.