Among the many processes involved in galaxy evolution, those of bar formation, quenching, and feedback from an active galactic nucleus (AGN) seem to be connected, however, the nature of these relations remains unclear. In this work, we aim to elucidate them by studying the formation of a barred galaxy in a major merger of two disks in the IllustrisTNG simulations. This merger involves a coalescence of two supermassive black holes and a sudden switch to the kinetic mode of AGN feedback implemented in the simulations, which leads to the removal of the gas from the inner part of the galaxy, followed by quenching of star formation and the formation of the bar. This causal relation between AGN feedback and bar formation explains a number of correlations observed in the data, such as the higher frequency of bars among red spirals and the presence of central gas holes in barred galaxies. In such a picture, the bars do not feed the black holes, so their presence does not increase the AGN strength, and they do not cause quenching. However, bars do form in regions characterized by a low gas fraction resulting from AGN feedback. This scenario is probably applicable to many barred galaxies, not only those formed in major mergers.