According to one embodiment, a semiconductor device includes a first terminal, a second terminal, and a first circuit. The first circuit includes a first switch element having a first end coupled to a first node to which a first voltage is supplied, a second end coupled to the first terminal, and a gate coupled between the first node and the second terminal, and a second switch element coupled between the first node and the first terminal. The first circuit is configured to switch the first switch element from OFF state to ON state when supply of the first voltage is interrupted, and switch the second switch element from OFF state to ON state while maintaining the first switch element in ON state when a voltage of the first terminal changes to a second voltage.