Shakespeare's main sources for Twelfth Night are an anonymous Italian play, Gl'Ingannati (The Deceived), printed in 1537 and/or Barnaby Riche's "Apolonius and Silla," printed in 1581 (based on Gl'Ingannati).  Below is a comparison of the three.

Twelfth Night

Gl'Ingannati

"Apolonius and Silla"

Character:

Viola/Cesario
Sebastian
Duke Orsino
Lady Olivia

 

Lelia/Fabio
Fabrizio
Flamino
Isabella

 

Silla/Silvo
Silvo
Apolonius
Julina

Plot:

Viola & Sebastian are separated during a shipwreck

 

Lelia & Fabrizio are separated during the sack of Rome in 1527; Lelia is 13 yrs old

 

Silla falls in love with Duke Apolonius while he stops Cyprus during his return from a war.   Silla wants him so in secret she boards a ship with her servant Pedro (disguised as brother and sister) to visit him (in Constantinople).  The captain tries to rape her, she calls on God, the ship is wrecked.
Viola disguises herself as a boy (Cesario) for protection and to become employed by Duke Orsino, which she does and is then sent to woo the Countess Olivia (within this time Viola has fallen in love with the Duke)
Three years later, Lelia is placed in a convent by her father; she escapes and disguises herself as a boy (Fabio),  and serves Flaminio (who sends her to woo Isabella)
  Silla dresses herself in male clothing (the captain's trunk is the only other thing to survive the wreck), assumes the name of her real brother Silvio and enters Apolonius' service (he sends her to woo the wealthy widow Julina) 

 

Olivia falls instantly in love with "Cesario" and informs him that if he wishes to come again, Olivia will see him--Cesario does not return or receive Olivia's affections.
Isabella falls in love with "Fabio", who receives Isabella's affection as long as Isabella rejects Flaminio
Julina falls in love with "Silvio". Silla suffers and does not return Julina's affections.
Sebastian shows up and is mistaken by the servants and by Olivia as being Cesario; Olivia pleads with him to marry her, he accepts--and they immediately get married.
Leila's twin, Fabrizio shows up and the old men think that he is the escaped Lelia, lock him in a room with Isabella; after which he and Isabella must  become betrothed
The real Silvio, looking for his sister, shows up at Constantinople, where he meets Julina in a park. She mistakes him for the count's page and invites him to supper. They dine, and then go to bed together, Julina conceives a child. Silvio leaves town in haste the next morning (afraid that he was mistaken for someone else). 
Cesario/Viola and Duke Orsino enter Olivia's estate; Olivia states that she and Cesario are married, Orsino turns on Cesario stating that he will have revenge, Cesario denies that they are married and swears allegiance to Orsino; Olivia calls for the priest to prove that they are married; Sebastian enters, he and Viola reunite, Viola's true identity is revealed, Orsino asks Viola to marry him.
Flaminio finds out that Isabella and Fabrizio are engaged and is outraged. He is persuaded not to take revenge by "Fabio" and instead marries Lelia
Julina realizes she is pregnant and goes to plead before Duke Apolonius, who has thrown his "Silvio" in prison after hearing from the gossip of servants his page's greater success in love. Anger erupts, Apolonius draws his sword and threatens to kill "Silvio" unless "he" marries Julina. Silla is forced to reveal herself (by stripping to the waist), and Apolonius, taken with her faithfulness, marries her. Silvio hears tales of these strange events, and eventually returns to Constantinople, where he marries the grieving Julina and they all live happily ever after.

Other Differences:

Viola has never met Duke Orsino

 

Flaminio is Lelia's beloved and then shifts his affection to Isabella

 

Silla falling in love with Apolonius causes the story to happen
Viola is an orphan, who believes to have also lost her brother
Lelia's father has betrothed her to Isabella's father (a much older man)
Silla's father is the Duke of Cyprus