President Barack Obama, in a rare public acknowledgment of secret efforts to combat terrorism, on Friday defended a pair of highly classified surveillance programs as necessary to protect Americans at the price of only "modest encroachments" on personal privacy.

The techniques that intelligence agents use to gather data about phone calls and certain foreign Internet communications—which were discussed in news reports this week—have been vetted by the courts and Congress, Mr. Obama said. But he added that he would...