Heat the oven to 350°F (175°C). Grease a 9x13-inch baking dish.
Bring a large pot of water to a boil and add 2 teaspoons salt. Add the green beans and cook for 4–5 minutes, until bright green and crisp-tender. Drain, rinse under cold running water until cool, and drain well.
Melt the butter in a large skillet over medium-high heat. Add the mushrooms and cook for 6–8 minutes, stirring occasionally, until browned and their liquid has cooked off. Add the shallot and garlic and cook for 1–2 minutes, until soft.
Sprinkle the flour over the mushrooms and stir for 1 minute. Slowly whisk in the broth, then the milk. Simmer for 3–5 minutes, stirring often, until the sauce thickens enough to coat a spoon.
Remove from the heat and stir in the Parmesan, 1/2 teaspoon salt and the pepper.
Add the green beans and 1 cup of the fried onions to the skillet and stir to coat. Spread the mixture in the baking dish.
Bake uncovered for 25 minutes, until bubbling at the edges and the center reaches 165°F (74°C).
Scatter the remaining fried onions over the top and bake for 5–10 minutes more, until the onions are deep golden. Rest for 5 minutes before serving.