Several ultrasound (US) prostate cancer localization methods are emerging, opening opportunities for targeted biopsies and focal therapy. However, before any of these methods, like elastography or contrast-enhanced US, can be introduced into clinical practice, accurate validation is required. The current gold standard for validation is histological assessment of the prostate after radical prostatectomy. Therefore, a 3D registration of histological and US data is required. This task is complicated by misalignment between histology slices and ultrasound imaging planes, pressure caused by the adopted transrectal US probe, and deformation and volume change during fixation in formalin solution. In this work, we introduce a dedicated 3D algorithm, automatically registering histology and ultrasound data. Because there is no information available between histology slices, and internal landmarks are not consistently present in US images, registration is based on outer-contours shape only. A 3D surface model of the prostate in constructed, based on manually outlined contours in a transrectal sweep video and a longitudinal image. Also, a similar model is constructed from the histology slices, including cancerous areas marked by a pathologist. Registration of the models is then performed in three steps: affine registration, elastic surface registration, and internal registration. In-vitro validation of the algorithm was performed by inserting rubber wires into four prostate mimicking phantoms and applying probe pressure. The resulting registration accuracy was 1.6 mm, which is considerably smaller than the histology slicing resolution of 4 mm.