In this thesis, we consider two main subjects: the refined BPS invariants of Calabi-Yau threefolds, and three-dimensional Chern-Simons theory with complex gauge group. We study the wall-crossing behavior of refined BPS invariants using a variety of techniques, including a four-dimensional supergravity analysis, statistical-mechanical melting crystal models, and relations to new mathematical invariants. We conjecture an equivalence between refined invariants and the motivic Donaldson-Thomas invariants of Kontsevich and Soibelman. We then consider perturbative Chern-Simons theory with complex gauge group, combining traditional and novel approaches to the theory (including a new state integral model) to obtain exact results for perturbative partition functions. We thus obtain a new class of topological invariants, which are not of finite type, defined in the background of genuinely nonabelian flat connections. The two main topics, BPS invariants and Chern-Simons theory, are connected at both a formal and (we believe) deeper conceptual level by the striking central role that the quantum dilogarithm function plays in each.