The question of optimal operation of wave-energy converters has been a key issue since modern research on the topic emerged in the early 1970s, and criteria for maximum wave-energy absorption soon emerged from frequency domain analysis. However, constraints on motions and forces give the need for time-domain modeling, where numerical optimization must be used to exploit the full absorption potential of an installed converter. A heaving, semisubmerged sphere is used to study optimal constrained motion of wave-energy converters. Based on a linear model of the wave-body interactions, a procedure for the optimization of the machinery force is developed and demonstrated. Moreover, a model-predictive controller is defined and tested for irregular sea. It repeatedly solves the optimization problem online in order to compute the optimal constrained machinery force on a receding horizon. The wave excitation force is predicted by use of an augmented Kalman filter based on a damped harmonic oscillator model of the wave process. It is shown how constraints influence the optimal motion of the heaving wave-energy converter, and also how close it is possible to approach previously published theoretical upper bounds. The model-predictive controller is found to perform close to optimum in irregular waves, depending on the quality of the wave force predictions. An absorbed power equal to or larger than 90% of the ideal constrained optimum is achieved for a chosen range of realistic sea states. Under certain circumstances, the optimal wave-energy absorption may be better in irregular waves than for a corresponding regular wave having the same energy period and wave-power level. An argument is presented to explain this observation.