Federal prosecutors filed criminal charges against Theranos Inc. founder Elizabeth Holmes and the blood-testing company’s former No. 2 executive, alleging that they defrauded investors out of hundreds of millions of dollars and also defrauded doctors and patients.

The indictments of Ms. Holmes and Ramesh “Sunny” Balwani, Theranos’s former president and chief operating officer who was also Ms. Holmes’s boyfriend, are the culmination of a 2½-year investigation by the U.S. attorney’s office in San Francisco, sparked by articles...