We propose and design a practical modulation-coded (MC) physical-layer network coding (PNC) scheme to approach the capacity limits of Gaussian and fading two-way relay channels (TWRCs). In the proposed scheme, an irregular repeat–accumulate (IRA) MC over $\textrm{GF}(q)$ with the same random coset is employed at two users, which directly maps the message sequences into coded PAM or QAM symbol sequences. The relay chooses appropriate network coding coefficients and computes the associated finite-field linear combinations of the two users' message sequences using an iterative belief propagation algorithm. For a symmetric Gaussian TWRC, we show that, by introducing the same random coset vector at the two users and a time-varying accumulator in the IRA code, the MC-PNC scheme exhibits symmetry and permutation-invariant properties for the soft information distribution of the network-coded message sequence (NCMS). We explore these properties in analyzing the convergence behavior of the scheme and optimizing the MC to approach the capacity limit of a TWRC. For a block fading TWRC, we present a new MC linear PNC scheme and an algorithm used at the relay for computing the NCMS. We demonstrate that our developed schemes achieve near-capacity performance in both Gaussian and Rayleigh fading TWRCs. For example, our designed codes over GF(7) and GF(3) with a code rate of 3/4 are within 1 and 1.2 dB of the TWRC capacity, respectively. Our method can be regarded as a practical embodiment of the notion of compute-and-forward with a good nested lattice code, and it can be applied to a wide range of network configurations.