A fundamental challenge for quantum information processing is reducing the impact of environmentally induced errors. Here we demonstrate a quantum error detection and rejection protocol based on the idea of quantum uncollapsing, using this protocol to reduce the impact of energy relaxation owing to the environment in a three-qubit superconducting circuit. We encode quantum information in a target qubit, and use the other two qubits to detect and reject errors caused by energy relaxation. This protocol improves the storage time of a quantum state by a factor of roughly three, at the cost of a reduced probability of success. This constitutes the first experimental demonstration of the algorithm-based improvement in the lifetime of a quantum state stored in a qubit.