Ned Stark was killed b/c he discovered Robert’s children weren’t his children and were products of incest between Cersei and Jaime Lannister. Instead of doing something about it right away by telling Robert, he tried to give Cersei a chance to get out of dodge since he knew Robert would have her, Jaime, and all three kids killed (he kept thinking about the murdered Targaryen children in the book). So he told Cersei what he knew, and she turned the tables on him quickly by having Robert killed and Ned thrown in prison.
He also told Joffrey to his face that he was a bastard. Ned was given a plea deal to go to The Wall, he took it, and Joffrey double-crossed him and had him beheaded.
See post 61