It's difficult to be absolutely specific about answering this question, because we're not 100% sure of the dates Shakespeare's plays were written and first performed.
We do know that Shakespeare started by writing comedies and histories, including the Henry VI plays, which are less complex in characterisation and similar to an earlier form of history drama (cf Tamburlaine the Great) written by Marlowe, a writer who much influenced Shakespeare in his 'mighty lines' of verse. The three Henry VI plays are usually dated to the early 1590s.
Shakespeare's great tragedies came later, Hamlet, King Lear, Othello and Macbeth all coming between 1599-1605. Shakespeare also continues to write histories (though less so towards the end of his life) and comedies - though his comedies become notably darker and more complex.
His later career shows his absolute mastery of playwrighting: so much so that he actively plays with and complicates genres. He writes comedies with real pain and unhappiness in them (Twelfth Night, Much Ado About Nothing) - which, in short, take on elements of tragedy. He writes plays which fit no easy categorisation like The Merchant of Venice and Measure for Measure. And he writes, in his final years of work, three plays - The Tempest, Cymbeline, and The Winter's Tale - which are a genre all of their own: plays which deal with bitter hardship and life's difficulties only to resolve in a hesitant but gloriously warm-hearted optimism.
In short: Shakespeare started off by following the rules of genre, and gradually became their master - and then dared to break them and think outside the box.