We prove a system of relations in the Grothendieck ring of the category $${\mathcal{O}}$$ O of representations of the Borel subalgebra of an untwisted quantum affine algebra $${U_q(\widehat{\mathfrak{g}})}$$ Uq(g^) introduced in Hernandez and Jimbo (Compos Math 148:1593–1623, 2012). This system was discovered, under the name $${Q\widetilde{Q}}$$ QQ~ -system, in Masoero et al. (Commun Math Phys 344:719–750, 2016; Commun Math Phys 349:1063–1105, 2017), where it was shown that solutions of this system can be attached to certain $${^L\widehat{\mathfrak{g}}}$$ Lg^ -affine opers, introduced in Feigin and Frenkel (Adv Stud Pure Math 61:185–274, 2007), where $${^L\widehat{g}}$$ Lg^ is the Langlands dual affine Kac–Moody algebra of $${\widehat{\mathfrak{g}}}$$ g^ . Together with the results of Bazhanov et al. (Commun Math Phys 200:297–324, 1999; Nucl Phys B 622:475–547 2002) which enable one to associate quantum $${\widehat{\mathfrak{g}}}$$ g^ -KdV Hamiltonians to representations from the category $${\mathcal{O}}$$ O , this provides strong evidence for the conjecture of Feigin and Frenkel (Adv Stud Pure Math 61:185–274, 2007) linking the spectra of quantum $${\widehat{\mathfrak{g}}}$$ g^ -KdV Hamiltonians and $${^L\widehat{\mathfrak{g}}}$$ Lg^ -affine opers. As a bonus, we obtain a direct and uniform proof of the Bethe Ansatz equations for a large class of quantum integrable models associated to arbitrary untwisted quantum affine algebras, under a mild genericity condition. We also conjecture analogues of these results for the twisted quantum affine algebras and elucidate the notion of opers for twisted affine algebras, making a connection to twisted opers introduced in Frenkel and Gross (Ann Math 170:1469–1512, 2009).