A former Google engineer is accusing the company of firing him after he spoke out about incidents of racism, sexism and harassment.

Tim Chevalier is suing Google (GOOGL) for retaliation, wrongful termination and failure to prevent discrimination and harassment, according to a lawsuit filed in San Francisco on Wednesday.

Silicon Valley -- and Google in particular -- has been shaken by fierce debates over diversity issues. Highly charged arguments between Google employees have at times burst into public view as the company wrestles with how to address the concerns.

The lawsuit by Chevalier, who identifies as transgender and disabled, claims Google's culture is discriminatory. He alleges that some employees use the company's internal social-networking and messaging systems to belittle and bully women, people of color and LGBTQ colleagues.

"Chevalier pushed back on the online bullying he and others were experiencing, using the same internal messaging systems to try to educate his employer and coworkers on how to change Google's working conditions to be inclusive and supportive of underrepresented minorities, such as himself," the lawsuit says.

His lawsuit alleges that rather than trying to address the concerns he was raising about other employees' behavior, Google fired him in November, citing the political nature of his posts.

"It is a cruel irony that Google attempted to justify firing me by claiming that my social networking posts showed bias against my harassers," Chevalier said in a statement provided by his lawyers. "The anti-discrimination laws are meant to protect marginalized and underrepresented groups -- not those who attack them."

Related: Google hit with revised gender pay lawsuit

Google spokeswoman Gina Scigliano declined to comment directly on Chevalier's allegations. She said that lively debate is important to Google's culture, but that there are limits.

"All employees acknowledge our code of conduct and other workplace policies, under which promoting harmful stereotypes based on race or gender is prohibited," Scigliano said in a statement. "This is a very standard expectation that most employers have of their employees. The overwhelming majority of our employees communicate in a way that is consistent with our policies. But when an employee does not, it is something we must take seriously. We always make our decision without any regard to the employee's political views."

In the lawsuit, which was first reported by tech news site Gizmodo, Chevalier alleges that some Googlers would call coworkers "immoral" because of their sexual orientation. Employees also questioned the competency of women and minorities on internal message boards, he said.

Related: Engineers sue Google for allegedly discriminating against white men and conservatives

"Company social networking forums can be incredibly useful, but employers have an obligation to prevent them from becoming a cesspool of bullying and harassment," David Lowe, an attorney for Chevalier, said in a statement. "Firing the employee who pushed back against the bullies was exactly the wrong step to take."

Debates inside Google about diversity issues erupted in August when one of the company's senior engineers at the time, James Damore, published a controversial memo claiming women are underrepresented in technology because of psychological and biological differences, not sexism.

In his memo, Damore claimed to "value diversity and inclusion," but he took issue with Google's approach, which he described as overly political and alienating to "non-progressives."

Damore, who was fired over the controversy, and another former Google engineer, David Gudeman, are suing the company, alleging that it discriminates against white men and conservatives.

Chevalier waded into the internal debates over Damore's memo last summer, according to his lawsuit. It says that in September, a Google human resources representative spoke with Chevalier about some of his emails and posts on internal forums regarding the memo and other politically charged subjects.

Google is also facing a gender-pay lawsuit claiming the company paid women less than their male counterparts.