A terminal-state optimal control problem for semilinear parabolic equations is studied in this paper. The control objective is to track a desired terminal state and the control is of the distributed type. A distinctive feature of this work is that the controlled state and the target state are allowed to have nonmatching boundary conditions. The existence of an optimal control solution is proved. We also show that the optimal solution depending on a parameter $\gamma$ gives solutions to the approximate controllability problem as $\gamma \rightarrow 0$. Error estimates are obtained for semidiscrete (spatially discrete) approximations of the optimal control problem. A gradient algorithm is discussed and numerical results are presented.