The plasma vertical position in a tokamak can be open-loop unstable with time-varying dynamics. The limitation in the output power of the control amplifier makes the time-varying unstable system particularly difficult to control. Fixed-coefficient linear controllers usually fail to maintain control in the presence of large disturbances, like edge-localized modes (ELMs), which saturate the amplifier output. During the saturation period, the vertical position of the plasma will grow exponentially with the unstable eigenvalue and may reach values that cannot be controlled by the energy provided by the control amplifier, which is limited by practical constraints. The primary sources of disturbances and measurement noise that effect the vertical position are the ELMs and the 600-Hz noise from the thyristor power supplies. The former are present in the form of pulses and appear during high-energy confinement plasma configurations.  A novel nonlinear controller for the vertical position based on a discrete adaptive near-time optimum control algorithm (DANTOC) is used to stabilize the system, to maximize the stability region, and to provide robustness with respect to the aforementioned sources of disturbances and measurement noise. The controller is tested in simulation for the Joint European Torus tokamak, and the results demonstrate its feasibility in controlling the vertical position for different plasma configurations. The controller is also tested on the COMPASS-D tokamak, and the results demonstrate the improvement with respect to a simple linear proportional and derivative controller in the presence of disturbances and measurement noise.