This paper proposes a new Peak Shaving algorithm in combination with a continuous battery peak power estimation algorithm for a battery energy storage system (BESS). The objective of the proposed Peak Shaving algorithm is to avoid energy exchanges when the output power is considered to be too high. Therefore, the algorithm allows configuring the power limits for the system operation. However, in extreme situations, the BESS might no longer be able to follow the algorithm commands and the power will surpass this limit. In these situations, the proposed dynamic minimum voltage tracking algorithm ensures that the maximum available power is extracted from the BESS, thus reducing the total output power. The proposed control system has been experimentally tested on a real-time microgrid. Results show that the proposed Peak Shaving algorithm allows to easily limit power exchanges between the microgrid and the main grid. Moreover, combining it with the dynamic minimum voltage tracking algorithm ensures that the power surplus, with reference to the defined limit, is minimized.