Preheat an oven to 350 degrees F (175 degrees C). Grease a 2-quart baking dish.
Place the sweet potatoes into a large pot and cover with water. Bring to a boil over high heat, then reduce heat to medium-low, cover, and simmer until tender, about 20 minutes. Drain and allow to steam dry for a minute or two. Mash sweet potatoes in a large bowl. Stir in the brown sugar, 1/4 cup softened margarine, 3 eggs, vanilla extract, and milk. Beat until fluffy. Pour into prepared baking dish. Mix flour, 1/4 cup melted margarine, pineapple, white sugar, and 1 egg together in a bowl. Spoon over the sweet potato mixture.
Bake in the preheated oven until golden brown, about 40 minutes.