Multilayered Josephson junctions are modeled in the context of a field theory, and dynamics of Josephson vortices trapped inside insulators are studied. Starting from a theory consisting of complex and real scalar fields coupled to a U(1) gauge field which admit parallel N − 1 domain-wall solutions, Josephson couplings are introduced weakly between the complex scalar fields. The N − 1 domain walls behave as insulators separating N superconductors, where one of the complex scalar fields has a gap. We construct the effective Lagrangian on the domain walls, which reduces to a coupled sine-Gordon model for well-separated walls and contains more interactions for walls at short distance. We then construct sine-Gordon solitons emerging in an effective theory in which we identify Josephson vortices carrying singly quantized magnetic fluxes. When two neighboring superconductors tend to have the same phase, the ground state does not change with the positions of domain walls (the width of superconductors). On the other hand, when two neighboring superconductors tend to have π -phase differences, the ground state has a phase transition depending on the positions of domain walls; when the two walls are close to each other (one superconductor is thin), frustration occurs because of the coupling between the two superconductors besides the thin superconductor. Focusing on the case of three superconductors separated by two insulators, we find for the former case that the interaction between two Josephson vortices on different insulators changes its nature, i.e., attractive or repulsive, depending on the positions of the domain walls. In the latter case, there emerges fractional Josephson vortices when two degenerate ground states appear due to spontaneous charge-symmetry breaking, and the number of the Josephson vortices varies with the position of the domain walls. Our predictions should be verified in multilayered Josephson junctions.