Container terminals are exchange hubs that interconnect many transportation modes and facilitate the flow of containers. Among other elements, terminals include a yard which serves as temporary storage space. In the yard, containers are piled up by cranes to form blocks of stacks. During the shipment process, containers are carried from the stacks to ships following a given sequence. Hence, if a high priority container is placed below low priority ones, such obstructing containers have to be moved (relocated) to other stacks. Given a set of stacks and a retrieval sequence, the aim in the Pre-marshalling Problem (pmp) is to sort the initial configuration according to the retrieval sequence using a minimum number of relocations, so that no new relocations are needed during the shipment. The objective in the Block Relocation Problem (brp) is to retrieve all the containers according to the retrieval sequence by using a minimum number of relocations. This paper presents a new unified integer programming model for solving the pmp, the brp, and the Restricted brp (r-brp) variant. The new formulations are compared with existing mathematical models for these problems, as well as with other exact methods that combines combinatorial lower bounds and the branch-and-bound (B&B) framework, by using a large set of instances available in the literature. The numerical experiments * Corresponding author: Tel. +33 1 4940 4082.show that the proposed models are able to outperform the approaches based on mathematical programming. Nevertheless, the B&B algorithms achieve the best results both in terms of computation time and number of instances solved to optimality.