This study investigates how digital transformation and organizational agility influence sustainable business performance in Indonesian Small and Medium-sized Enterprises (SMEs), emphasizing the mediating role of legality. Drawing on dynamic capabilities theory, the research explores how digital technologies and agile practices contribute to resilience and long-term competitiveness. Using a quantitative approach, data were collected from 453 SMEs across Yogyakarta through structured questionnaires administered in hybrid offline-online sessions. Thematic analysis via NVivo revealed a conceptual framework positioning agility as a critical mediator between digital adoption and business sustainability. The findings highlight that SMEs leveraging digital tools demonstrate greater responsiveness, operational flexibility, and innovation capacity. Notably, legal compliance emerged as a foundational enabler: legally registered SMEs were more effective in adopting digital strategies, accessing institutional support, and navigating regulatory environments. This underscore the role of legality not only as a contextual factor but as a strategic asset enhancing digital and agile capabilities. The study contributes to entrepreneurial strategy literature by integrating digital transformation, agility, and legality into a cohesive model for sustainable SME performance. Practical implications suggest that SMEs should prioritize digital investment alongside legal formalization to maximize their strategic agility and long-term success in volatile markets.