Automatic liver segmentation from abdominal computed tomography (CT) images is a fundamental task in computer-assisted liver surgery programs. Many liver segmentation algorithms are very sensitive to fuzzy boundaries and heterogeneous pathologies, especially when the data are scarce. To solve these problems, we propose an automatic liver segmentation framework based on three-dimensional (3D) convolutional neural networks with a hybrid loss function. Two networks are incorporated in our method with the first being a liver shape autoencoder that is trained to obtain compressed codes of liver shapes, and the second being a liver segmentation network that is trained with a hybrid loss function. The design of the hybrid loss function is comprised of three parts. The first part is an adaptively weighted cross-entropy loss, which pays more attention to misclassified pixels. The second part is an edge-preserving smoothness loss, which guarantees that the adjacent pixels with the same label have similar outputs, while dissimilar for pixels with different labels. The third part of the loss is a shape constraint to model high-level structural differences based on the learned shape codes. Both networks use 3D operations for data processing. In our experiments, data augmentation is performed at both the training and the test stage. We extensively evaluated our method on two datasets: the Segmentation of the Liver Competition 2007 (Sliver07), and the Combined (CT-MR) Healthy Abdominal Organ Segmentation (CHAOS) Challenge. Finally, with only 20 training scans, we achieved the best score of 82.55 on the Sliver07 challenge, and a score of 83.02 on the CHAOS challenge. In this study, we proposed a novel hybrid loss to overcome the difficulties in liver segmentation. The quantitative and qualitative results demonstrate that our method is highly suited for pathological liver segmentation, even when trained with a small dataset.