The urgent task of mitigating global warming requires efforts to reduce carbon emissions. The key is to incorporate relevant measures into urban planning strategies. Building form not only affects the daily activities of inhabitants but also significantly influences carbon emission patterns within surrounding areas. Consequently, it is crucial to understand how building form impacts carbon emission patterns. The nonlinear threshold effects of building form on carbon emissions have not been extensively studied. This study aims to address this void by examining the nonlinear connection between carbon emissions and building form and identifying specific threshold effects by using random forest and partial dependence plots. We conducted a comparative analysis of various machine learning models, including gradient boosting decision tree, extreme gradient boosting, and random forest. The random forest demonstrated the best fit. Further analysis indicated that urban building form has a substantial impact on urban carbon emissions. Notably, the floor area ratio was the most critical factor, accounting for 12.93 % of the relative importance in influencing carbon emissions. This was followed by the building congestion degree (12.24 %), the high building density (11.64 %), and the sky view factor (10.65 %). Collectively, these top four indicators, all related to building form, underscore their significant role in determining urban carbon emissions. In addition, nonlinear threshold effects were observed between the building form indicators and carbon emissions. These effects manifested as distinct patterns, such as platform, V-shaped, and N-shaped relationships, characterized by alterations in influencing trends, frequency, and distribution of thresholds. Among these relationships, platform and V-shaped types were observed with greater frequency, whereas N-shaped relationships, which are more complex, were encountered less frequently. Our findings provide insights for urban policymakers to develop targeted strategies to mitigate carbon emissions by optimizing building form in urban contexts.