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."
Twitter discovered the bug a few weeks ago and has reported it to some regulators, said the person, who was not authorised to discuss the matter.
Twitter practice is to store passwords encrypted, or "hashed," so they are masked to even people inside the company, Twitter chief technology officer Parag Agrawal explained in a blog post.
"Due to a bug, passwords were written to an internal log before completing the hashing process," he said.
"We found this error ourselves, removed the passwords, and are implementing plans to prevent this bug from happening again."
The San Francisco-based internet company did not specify how many passwords were exposed or how long the glitch made data vulnerable to snooping.
"Out of an abundance of caution, we ask that you consider changing your password on all services where you've used this password," Agrawal told users.
The disclosure comes as lawmakers and regulators around the world scrutinise 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.

Twitter message. Source: Twitter
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 one 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.