This paper studies the empty container repositioning (ECR) problem considering the exchange of slots and empty containers among liner shipping companies. It is common for an individual shipping company to seek an optimal solution for ECR and cargo routing to maximize its own benefits. To achieve cooperation among shipping companies, a multi-stage solution strategy is proposed. With the inverse optimization technique, the guide leasing prices of slots and empty containers among shipping companies are derived considering the schedule of vessels and cargo routing. Based on the guide leasing price, a cooperative model is formulated to minimize the total cost, which includes the transportation cost for laden containers, the inventory holding cost, the container leasing cost, and the repositioning cost. All the involved shipping companies are expected to follow the best solution of ECR and cargo routing to achieve a cooperative and stable optimum. A real-world shipping network operated by three liner shipping companies is used as a case study with promising numerical results.