In this letter, the resource allocation problem for uplink multi-carrier non-orthogonal multiple access (NOMA) in device-to-device (D2D) underlaid cellular networks is investigated. Due to the existence of D2D pairs, NOMA users are subject to varying degrees of interference. We formulate the problem as a Nash bargaining game to maximize the Nash product of each user. We propose an iterative algorithm applying Karush–Kuhn–Tucker conditions to solve the power allocation problem and modeling the user clustering as a Hedonic coalition game. Simulation results verify the convergence of the proposed algorithms. Besides, the algorithms achieve near-optimal performance compared to exhaustive search method and the throughput and fairness in NOMA are both higher than those in orthogonal multiple access.