The social network said it had fixed the glitch and that an internal investigation had found no indication passwords were stolen or misused by insiders, but it urged all users to consider changing their passwords "out of an abundance of caution."
The blog did not say how many passwords were affected. But a person familiar with the company's response said the number was "substantial" and that they were exposed for "several months.
We recently found a bug that stored passwords unmasked in an internal log. We fixed the bug and have no indication of a breach or misuse by anyone. As a precaution, consider changing your password on all services where you’ve used this password. https://t.co/RyEDvQOTaZ— Twitter Support (@TwitterSupport) May 3, 2018
Twitter discovered the bug a few weeks ago and has reported it to some regulators, said the person, who was not authorized to discuss the matter.
The disclosure comes as lawmakers and regulators around the world scrutinize the way that companies store and secure consumer data, after a string of security incidents that have come to light at firms including Equifax Inc, Facebook Inc and Uber.
The European Union is due to start enforcing a strict new privacy law, known as the General Data Protection Regulation, that includes steep fees for violating its terms.
The glitch was related to Twitter's use of a technology known as "hashing" that masks passwords as a user enters them by replacing them with numbers and letters, according to the blog.
A bug caused the passwords to be written on an internal computer log before the hashing process was completed, the blog said.
"We are very sorry this happened," the Twitter blog said.
Twitter's share price was down 1 percent in extended trade at $30.35, after gaining 0.4 percent during the session.
The company advised users to take precautions to ensure that their accounts are safe, including changing passwords and enabling Twitter's two-factor authentication service to help prevent accounts from being hijacked.