Apple is “a staunch advocate for our customers’ privacy and personal safety,” Mr. Cook said at the meeting. “We do these things because they are the right things to do. Being hard doesn’t scare us.”

Technology’s largest companies are now also aligning themselves with Apple. Facebook, Google, Microsoft, Twitter and Yahoo have said they will file one or more briefs in California federal court next week in support of Apple. More could join.

Cindy Cohn, the executive director of the Electronic Frontier Foundation, who was also at the meeting, said she applauded Apple’s leadership in fighting for the security and privacy of customers. She said the foundation would file a brief supporting Apple’s refusal to comply with the court order.

During the shareholder meeting, an energized Mr. Cook, dressed in his customary blue oxford shirt and jeans, also noted that Apple had released new versions of its mobile and desktop operating systems, which have the advanced security and encryption features that have frustrated the law enforcement agents who want access to data on Apple’s devices. He said 77 percent of all active devices were using these most advanced and secure operating systems.