A mechanism of the interaction of benzoylacetylene with dithio- and diselenomalonamides has been proposed on the basis of quantum-chemical calculations in the framework of the density functional theory using the B3LYP/6-311++G(d,p) basis set taking into account solvent effects (AcOH) within the polarizable continuum model, PCM, with inclusion of the HCl molecule in the calculated space. It is shown that the reaction involves two stages to afford heterocyclic compounds of the dithiine and diselenine type