The microscopic origin of the large negative thermal expansion of cubic scandium trifluorides (ScF3) is investigated by performing a set of anharmonic free-energy calculations based on density functional theory. We demonstrate that the conventional quasiharmonic approximation (QHA) completely breaks down for ScF3 and the quartic anharmonicity, treated nonperturbatively by the self-consistent phonon theory, is essential to reproduce the observed transition from negative to positive thermal expansivity and the hardening of the R4+ soft mode with heating. In addition, we show that the contribution from the cubic anharmonicity to the vibrational free energy, evaluated by the improved self-consistent phonon theory, is significant and as important as that from the quartic anharmonicity for robust understandings of the temperature dependence of the thermal expansion coefficient. The first-principles approach of this study enables us to compute various thermodynamic properties of solids in the thermodynamic limit with the effects of cubic and quartic anharmonicities. Therefore, it is expected to solve many known issues of the QHA-based predictions particularly noticeable at high temperature and in strongly anharmonic materials.