WASHINGTON—Congress voted overwhelmingly Wednesday to override President Barack Obama’s veto of legislation that would let Americans sue foreign governments over terrorist attacks, the first such rebuke since the president took office.

The House voted 348-77 just hours after the Senate, in a 97-1 vote, moved to overturn Mr. Obama’s Friday veto of the bill. Families of the victims of the Sept. 11, 2001, terrorist attacks have long sought the right to sue Saudi Arabia for any alleged role in the attacks. The kingdom has denied...