If X and Y are equal almost surely, then they have the same distribution, but the reverse direction is not correct
Take $X$ and $Y$ with probabilities $P(X=1)=P(X=2)=P(Y=1)=P(Y=2)=0.5$ and which are independent. Then $$P(X=Y) = P(X=1, Y=1) + P(X=2,Y=2) =\\= P(X=1)P(Y=1)+P(Y=2)P(Y=2)=0.5,$$ meaning that $X=Y$ holds with probability $0.5$, not $1$.