SAN FRANCISCO — Alexander Macgillivray, Twitter’s chief lawyer, says that fighting for free speech is more than a good idea. He thinks it is a competitive advantage for his company.

That conviction explains why he spends so much of Twitter’s time and money going toe to toe with officers and apparatchiks both here and abroad. Last week, his legal team was fighting a court order to extract an Occupy Wall Street protester’s Twitter posts. The week before, the team wrestled with Indian government officials seeking to take down missives they considered inflammatory. Last year, Mr. Macgillivray challenged the Justice Department in its hunt for WikiLeaks supporters who used Twitter to communicate.

“We value the reputation we have for defending and respecting the user’s voice,” Mr. Macgillivray said in an interview here at Twitter headquarters. “We think it’s important to our company and the way users think about whether to use Twitter, as compared to other services.”

It doesn’t always work. And it sometimes collides awkwardly with another imperative Twitter faces: to turn its fire hose of public opinion into a profitable business. That imperative will become far more acute if the company goes public, and Twitter confronts pressures to make money fast and play nice with the governments of countries in which it operates; most Twitter users live outside the United States and the company is already opening offices overseas.