Let$S$be a closed Shimura variety uniformized by the complex$n$-ball associated with a standard unitary group. The Hodge conjecture predicts that every Hodge class in $${H^{2k} (S, \mathbb{Q})}$$ , $${k=0,\dots, n}$$ , is algebraic. We show that this holds for all degrees$k$away from the neighborhood $${\bigl]\tfrac13n,\tfrac23n\bigr[}$$ of the middle degree. We also prove the Tate conjecture for the same degrees as the Hodge conjecture and the generalized form of the Hodge conjecture in degrees away from an interval (depending on the codimension$c$of the subvariety) centered at the middle dimension of S. These results are derived from a general theorem that applies to all Shimura varieties associated with standard unitary groups of any signature. The proofs make use of Arthur’s endoscopic classification of automorphic representations of classical groups. As such our results rely on the stabilization of the trace formula for the (disconnected) groups $${GL (N) \rtimes \langle \theta \rangle}$$ associated with base change.