© 2014, Springer Science+Business Media New York. With the target of optimizing CO2 sequestration in underground reservoirs, we investigate constrained optimal control problems with partially miscible two-phase flow in porous media. Our objective is to maximize the amount of trapped CO2 in an underground reservoir after a fixed period of CO2 injection, while time-dependent injection rates in multiple wells are used as control parameters. We describe the governing two-phase two-component Darcy flow PDE system, formulate the optimal control problem and derive the continuous adjoint equations. For the discretization we apply a variant of the so-called BOX method, a locally conservative control-volume FE method that we further stabilize by a periodic averaging feature to reduce oscillations. The timestep-wise Lagrange function of the control problem is implemented as a variational form in Sundance, a toolbox for rapid development of parallel FE simulations, which is part of the HPC software Trilinos. We discuss the BOX method and our implementation in Sundance. The MPI parallelized Sundance state and adjoint solvers are linked to the interior point optimization package IPOPT, using limited-memory BFGS updates for approximating second derivatives. Finally, we present and discuss different types of optimal control results.