My personal favorite means? An elevated 1 tile wide long, long winding causeway between the fort entrance and the outside world, and with an increasing density of weapons traps as one proceeds along the causeway.
Start with a 1 weapon trap in the first tile, next gets 2, etc. Also, you can cover the causeway with a ballista battery if you want to make things stupidly complicated. Otherwise, almost any weapon for the traps will do as they are unlikely to score any damage in this case. The point being the megabeast should eventually dodge over the side of the causeway. Thus it has to be sufficiently elevated to extract severe damage from the fall. How many falls will it take? Place your bets.
Off topic and only tangentially related: megabeast aside, and if you're feeling sadistic, for low level minor threats don't elevate the causeway more than 1 z level high to avoid fall damage. And, use plenty of cutting types of weapon traps. Try watching a conga line of agitated Gray langurs first run, then hobble, crawl, and finally wiggle their repeating way across this setup. They'll be leaving ever larger piles of body parts while painting the landscape in bloody gore. It's amazing how many times the little guys try even in the face of crippling injuries with the promise of more before bleeding out. I find it both absolutely horrifying ... and strangely satisfying.