This paper introduces a decentralized model predictive controller (DMPC) to ensure power sharing and regulate dc bus voltage in dc microgrids (MGs) with constant power load (CPL). The proposed method replaces the conventional primary layer of dc MGs, i.e., inner loops and droop control, with a single optimal controller. A predictive automatic model of the system is realized for prediction purposes and to be used in the cost function. The control objectives are then incorporated in the cost function to attain an optimal state switching in each sampling time, hence regulating dc bus voltage and accurate sharing of current among the MG. The proposed solution provides the system with a fast dynamic response and zero steady state error. The effectiveness of proposed control is verified via hardware-in-the-loop real time experiments, and the results are compared with the conventional primary control.