The best master clock (BMC) algorithm is currently used to establish the master-slave hierarchy for the IEEE 1588 Precision Time Protocol (PTP). However, the BMC algorithm may create an unbalanced hierarchy that contains several boundary clocks with a large number of slaves in comparison to other clocks. The unbalanced hierarchy can cause problems, such as high communication load and high bandwidth consumption in boundary clocks. Additionally, the BMC algorithm does not provide any fast recovery mechanism in the case of a master failure. In this paper, we propose a novel balanced synchronization hierarchy with spare masters (BSHSM) algorithm to establish a balanced master-slave hierarchy and to provide a fast recovery mechanism in the case of master failures for the PTP. The BSHSM algorithm establishes the master-slave hierarchy with boundary clocks that have a balanced number of slaves. In doing so, it solves the problems caused by the unbalanced master-slave hierarchy. Additionally, the BSHSM algorithm provides a fast recovery mechanism by selecting a spare master for each boundary clock; this allows a boundary clock to immediately select a new master clock when its current master has failed or is disconnected. The fast recovery mechanism reduces the period of running freely and clock drift in clocks, improving the synchronization quality of the PTP. Various simulations were conducted using the network simulation OMNeT++ v4.6 to analyze, evaluate, and compare the performance of the BSHSM and BMC algorithms. The simulation results show that the synchronization hierarchy of the BSHSM algorithm is much more balanced than the BMC algorithm, and it also has a shorter period of recovery.