Accurate estimation of mud weight (MW) helps to conserve wellbore stability in real-time drilling operations. Determination of proper MW requires a correct understanding of the stress field, natural fractures, pore pressure, rock strength, borehole trajectories, etc. It is a problematic task especially in, highly inclined wells, deviated wells, and near salt formations due to uneven variations in wellbore stresses. Proper MWs are difficult to apply at target depths of the unstable formations because of uncertainties existing inside the wellbore. There are no reliable tools or techniques available that can precisely determine the optimum value of MW. This paper proposes a novel and more convenient approach to estimate the safe MW for deviated wells using surface measured data. In this study, Bagging and Random forest ensembles have been utilized to model the relationship between sensors measured variables and MW. The proposed framework has been trained and tested on real-time Norwegian post-drilling data. Artificial neural networks (ANNs) and support vector regression (SVR) have also been utilized in this study for comparison purposes. The analysis of prediction results clearly reveals that Random forest ensemble has acquired the highest coefficient of correlation and minimum estimation errors. The performance of Ensemble methods is found to be superior to the ANNs and SVR models. The proposed approach can be useful for the determination of MW required at different depths of reservoir formation and maintaining the wellbore stability during real-time operations.