Preheat the oven to 350°F (175°C).
Place the pre-made pie crust in the 9-inch pie dish and set aside.
In a mixing bowl, combine the granulated sugar, cocoa powder, flour, and salt. Whisk together until well mixed.
In a saucepan over medium heat, combine the milk and the dry mixture. Stir continuously to avoid lumps.
In a separate bowl, whisk the egg yolks. Once the mixture in the saucepan begins to thicken, take a small amount of it and gradually mix it with the egg yolks to temper them.
Slowly add the tempered egg yolk mixture back into the saucepan and continue stirring until the mixture thickens and comes to a gentle boil (about 2 minutes).
Remove the saucepan from the heat and add the vanilla extract and unsalted butter. Stir until the butter is completely melted and the filling is smooth.
Pour the chocolate filling into the prepared pie crust, smoothing the top with a rubber spatula.
Bake in the preheated oven for 25-30 minutes or until the filling is set (it may still jiggle slightly in the center).
Remove from the oven and allow to cool at room temperature for about 2 hours.
Once cooled, cover with plastic wrap and chill in the refrigerator for at least 2 hours before serving.
Serve chilled with a dollop of whipped cream and a sprinkle of chocolate shavings or cocoa powder on top, if desired.