There is a little switch that allows you to put the transmission into gear while depressing the brake pedal. If that switch is going out, or is not contacting the brake pedal correctly, it could stop you from putting the transmission into gear, or getting it fully into park allowing you to take the key out of the ignition.
Someone here replaced/repaired that switch a while ago and did a write up on it. I would have to do some hunting to find it if you need it.