The growing demand for low-emission maritime transport and efficient onboard energy management has intensified research into advanced control strategies for hybrid shipboard microgrids. These systems integrate both AC and DC power domains, incorporating renewable energy sources and battery storage to enhance fuel efficiency, reduce greenhouse gas emissions, and support operational flexibility. However, integrating renewable energy into shipboard microgrids introduces challenges, such as power fluctuations, varying line impedances, and disturbances caused by AC/DC load transitions, harmonics, and mismatches in demand and supply. These issues impact system stability and the seamless coordination of multiple distributed generators. To address these challenges, we proposed a hierarchical control strategy that supports sustainable operation by improving the voltage and frequency regulation under dynamic conditions, as demonstrated through both MATLAB/Simulink simulations and real-time hardware validation. Simulation results show that the proposed controller reduces the frequency deviation by up to 25.5% and power variation improved by 20.1% compared with conventional PI-based secondary control during load transition scenarios. Hardware implementation on the NVIDIA Jetson Nano confirms real-time feasibility, maintaining power and frequency tracking errors below 5% under dynamic loading. A comparative analysis of the classical PI and sliding mode control-based designs is conducted under various grid conditions, such as cold ironing mode of the shipboard microgrid, and load variations, considering both the AC and DC loads. The system stability and control law formulation are verified through simulations in MATLAB/SIMULINK and practical implementation. The experimental results demonstrate that the proposed secondary control architecture enhances the system robustness and ensures sustainable operation, making it a viable solution for modern shipboard microgrids transitioning towards green energy.