Answer:
If you have newer vehicle then it probably has a brake-shift interlock, which prevents you from shifting from park or neutral unless the brake pedal is pressed down. If there is anything on the instrument cluster that says "Press Bake to Shift From Park", then your car has an interlock.
The interlock uses a sensor on the brake pedal that sends a signal to a solenoid connected to the gear selector. It is common for either one of these components to fail. If you have access to or can find a service manual for you car, replacing the solenoid or the sensor should be relatively simple. Otherwise, have the car towed to a reputable garage.
Your problem could also be an issue with the shift linkage being too loose or binding. You can remove the bottom panels of the vehicle's dash and attempt to tighten or lubricate the shift linkage. Again having a service manual would be beneficial.
There is also a possibility of an issue inside the transmission. The transmission uses a parking pawl that manually holds the vehicle in place, and it is possible that the pawl got bent or the retract mechanism is damaged. A reputable transmission technician should be able to identify and repair any issues internal to the transmission.