In this paper, a new energy management algorithm has been suggested for the ships connected with alternative energies considering the smart electricity grid features. The algorithm focuses on the use of optimum energy source on the shipboard based on the priorities of authorities such as the most economic, environmental, or both criteria at the ports. The algorithm is performed in MATLAB, and several case studies are simulated to validate the results. The 5 maritime nations, which are at different regions: United States, Belgium, Turkey, China, and Australia, are taken into account in the case studies. The actual data of a bulk carrier ship have been used to achieve tangible results in the simulations. The results of the case studies are compared to determine the changes of energy cost and released emission to meet demand of electricity on the ships. Capital cost of the proposed concept is also given to make an economic evaluation. The results show that the ship energy management algorithm provides the significant economic and environmental advantages. This paper aims to contribute to the importance of the ships in the smart electricity grid concept for the maritime and electricity sector representatives.