In the present paper we investigate commutativity in prime rings and $3$-prime near-rings admitting a generalized derivation satisfying certain algebraic identities. Some well-known results characterizing commutativity of prime rings and $3$-prime near-rings have been generalized.