The occurrence of cascading failures poses significant risks to the stability and reliability of modern smart grids. This article presents a novel hybrid algorithm designed to assess and mitigate these failures. The technique combines advanced clustering algorithms, specifically Affinity Propagation Graph (APG) and Self-Propagating Graph (SPG), to detect critical nodes, and Unified Power Flow Controllers (UPFCs) to provide compensation to grid networks. The algorithm first uses APG to divide the network into clusters and considers the center bus as the critical node. If the center bus is not critical, SPG is applied to identify the critical node. This hybrid approach identifies the critical node in just 0.02 s (for both APG and SPG) and with improved accuracy compared to existing methods. After identifying critical nodes, UPFCs are strategically installed to regulate power flow and reduce the probability of cascading failures, with compensation taking approximately 0.14 s. Simulation results demonstrate the effectiveness of the proposed method in enhancing grid resilience and reducing the likelihood of cascading failures. By strategically deploying UPFCs at critical nodes, this approach ensures resilient grid operation in various scenarios. This research significantly contributes to the development of smart grid technologies by providing a comprehensive framework to address cascading failures in power distribution networks. The proposed method shows potential for improving the reliability and stability of power grids amid changing system dynamics and uncertainties.