Battery energy storage system makes seaport microgrids more reliable, flexible, and resilient. However, it is necessary to develop, test, and validate the functionality of battery energy storage controller in such a way that it balances power mismatch of demand and supply by charging and discharging the battery. This paper examines the performance of battery energy storage controller (BESC) to be employed in harbour grids in such a way that mismatch of power supply and load demand is compensated by charging and discharging the battery energy storage system. This controller can save energy efficiently and shave peak load demand in harbour grids where transmission and distribution systems have a limited power capacity. The controller of battery energy storage system is first developed offline in the MATLAB/Simulink, and then implemented with IEC61850 communication protocol for publishing and subscribing GOOSE messages. Moreover, to test the effectiveness of the proposed control algorithm of battery energy storage system, a real data from the local distribution system operator Vaasan Sähköverkko and harbour operator Kvarken port of Vaasa has been implemented. The simulation results show that the designed battery energy storage controller can balance power inside microgrid by charging and discharging of battery storage. The applied technique used in this paper is useful to validate the controller functionality in real time with the concept of simulation-in-loop (SIL), which is a practical approach, and it provides a cost-effective way to observe the performance of the controller.