Can I change what happens to Thane?
In my playthrough:
Thane was critically wounded by the Cerberus assassin on the Citadel. He died later in the Huerta Memorial Hospital.
Shepard and squad stood around being useless while Thane was fighting with the assassin. Is there any way I could have prevented this outcome?
There's only one way where Thane survives the attack:
If Captain Kirrahe survived Mass Effect's final mission, you'll meet him during the mission to recover the female Krogan. If you didn't talk to Thane prior to the attack on the Citadel, Kirrahe will intervene instead of Thane and die in his place.
However, I wouldn't mourn Thane's death. If you speak to Thane prior to the attack, you'll learn that he's near the end of his life regardless of what happens. He says that one doctor gave him 3 months to live 9 months ago. He also talks about his constant pain and feelings of suffocation. For him, this is likely an honorable and worthy end.