Let's consider an infinite swept wing with a sweep angle $\Lambda$. We can divide the freestream velocity ($V_\infty$) into two components: the component perpendicular to the sweep ($V_{\perp}$) and the component parallel to the sweep ($V_{||}$). Similarly, we will divide the exo-boundary layer velocity field around the wing ($V_e$) into the perpendicular component ($u_e$) and parallel component ($w_e$).

Graph cited from Drela, Flight Vehicle Aerodynamics.
Due to infinite span, the flow quantities along the swept coordinate ($z$) must be invariant. Therefore, the flow parallel to the wing sweep ($w_e$) must also be invariant and equal to the freestream component ($V_{||}$) everywhere.
Assuming that the flow outside of the boundary layer contains only weak shocks and is therefore isentropic (except at the shock), we can use the isentropic relationship to relate pressure field and velocity field. Here, everything with subscript $_e$ denotes flow quantities outside of the boundary layer:
$$p_e(x)=p_\infty \left(\frac{h_e}{h_\infty} \right)^{\gamma/(\gamma-1)}=p_\infty \left[ 1 + \frac{\gamma-1}{2}M_\perp^2 \left(1-\frac{u_e^2}{V_\perp^2} \right)\right]^{\gamma/(\gamma-1)}$$
where $h$ is enthalpy, $p$ is pressure, $M$ is Mach number, $\gamma$ is specific heats ratio.
Notice that the flow parallel to the wing sweep has no bearing on the pressure field; it's as if each wing section only sees the perpendicular flow. The same goes for effective 2D Mach ($M_\perp$), which is a net reduction from the freestream Mach ($M$) by a factor of $\cos\Lambda$. Since a reduction in Mach reduces the normal shock strength in the 2D section, or even removes the shock altogether, it leads to a reduction in wave drag compared to no sweep.
Below is the 2D drag curve vs. Mach for NACA 0012 from Euler solution. Local shock is obvious starting 2D free-stream Mach 0.65. This goes to show that decreasing effective 2D Mach lowers the overall wing drag via sweeping.

Graph cited from http://aerodesign.stanford.edu/aircraftdesign/drag/dragrise.html.
In a finite span wing, there will be gradient in $w_e$ that will lead to flow variation along the span. However, the principle of wave drag reduction through wing sweep readily applies.