Edward Woollard, 18, joined protesters who stormed the complex, housing the Conservative party headquarters, on 10 November.
Television pictures showed Woollard throwing an empty metal fire extinguisher from a seventh-floor rooftop as hundreds of people gathered in a courtyard below.
Woollard, of Dibden Purlieu, Hampshire, will serve at least half of his sentence for violent disorder in a young offenders institution.
He slumped forward as the sentence was handed down and his family were in floods of tears.
More than 60 demonstrators were arrested when trouble broke out after a peaceful demonstration and march.
Police, who had underestimated the scale of the demonstration, struggled to hold the line against the protesters on Millbank, near the houses of parliament.
Demonstrators broke into Millbank Tower, where windows were smashed and furniture destroyed.
Some reached the roof and hurled objects, including the fire extinguisher, down at the police lines.
Woollard was arrested in Southampton five days after the protests.
Judge Geoffrey Rivlin QC said: "There is no doubt that the disturbance was a very major one. It is perhaps ironic that the weapon that you threw down from the top of this very high building and which was calculated to inflame passions was a fire extinguisher.
"It is in my judgment extremely fortunate that your actions did not result in death or very serious injury either to a police officer or fellow protester."
He told Woollard the public had a right to protection from violence, and praised the teenager's mother for encouraging him to give himself up to police after he was identified in media coverage of the rioting.
Rivlin said: "It is deeply regrettable, indeed a shocking thing, for a court to have sentence a young man such as you to a substantial term of custody.
"But the courts have a duty to provide the community with such protection from violence as they can and this means sending out a very clear message to anyone minded to behave in this way that an offence of this seriousness will not be tolerated.
"The right of peaceful protest is a precious one. Those who abuse it and use the occasion to indulge in serious violence must expect a lengthy sentence of immediate custody."
He added: "Nevertheless I shall take into account in your favour the extraordinary and courageous conduct of your mother, which resulted in you giving yourself up to the police so quickly."
Rivlin also said he took into account the defendant's age, his guilty plea at the earliest opportunity and the fact that he had no previous convictions.