The M21A slide only comes off the frame rails IF you have released the barrel and tipped it up. Pulling it back with the barrel down does not release the slide by accident.
Did by any chance you try to dis-assemble it with the magazine still in the pistol? And then muscle it?
As a generality, if it feeds the first 3-4-5 rounds off the top and fails to fed the last 2-3-4 in the magazine, you have a mag spring problem. Or damaged mag feed lips.
As a further generality, there is no way to put it together wrong. The slide is either all the way down and in the two frame rail nubs or it isn't. The barrel is either locked down to guide the front of the slide or it isn't.
Use some CCI MiniMag 40RN to test it.
As to using a different mag and a different ammo and it is still not working, puzzlement. The guns are dirt simple and generally moron proof. Take a look at the magazine lips. Are they unbent, uncut up/knicked/chipped, and === parallel?
They are still made and Beretta still services them in Md.
(Or you may have installed both mag springs backwards. The free-longest limb of the spring has to support the front of the follower under the bullet end, NOT the rim end. That IS something that shows up in the last few rounds.)