"I am very happy to have reached this agreement," said the 29-year-old double world champion.
"I immediately felt comfortable within Ferrari and now it feels to me like a second family."
In signing such a lengthy deal, Alonso is convinced he will now remain with Ferrari for the rest of his F1 career.
"The intention is to finish my career with Ferrari and I can't imagine a better place to race," added Alonso. "I feel very privileged and very happy. Maybe in 2017 we can do another contract if I'm still quick and Ferrari are still happy with me.
"It's not a big change for me. I was feeling happy and comfortable. We started talking a week or two ago about the future. When two parties want to continue you find a decision very quickly.
"Stability is always good for an F1 team. Hopefully we can bring some success to Maranello.
"Ferrari have finished no lower than third in the championship virtually every year for a long time. This is one of the things Ferrari can offer to a driver. In the next six years I will try to enjoy my racing and hopefully we can have some success."
Ferrari president Luca di Montezemolo said: "It is a great pleasure to have renewed our agreement with a driver who has always demonstrated a winning mentality, even in the most difficult circumstances.
Ferrari can be champions - Alonso
"Fernando has all the required qualities, both technically and personally, to play a leading role in the history of Ferrari and I hope he will be enriching it with further wins very soon."
Last week, Di Montezemolo insisted that Ferrari would honour Felipe Massa's contract with the team which expires at the end of next season.
The Brazilian has been under pressure since Alonso's arrival but Massa has shown signs of recovering some of his best form this season out-scoring his team-mate in Malaysia and China.
Alonso, who will compete in his home Grand Prix in Barcelona this weekend, earned his and Ferrari's first podium finish of the season at the
Turkish Grand Prix on 8 May
, finishing third behind Red Bull duo Vettel and Mark Webber.
The result means he trails the German world champion Sebastian Vettel by 52 points after four races of the 2011 season.
Since winning the world championship with Red Bull, Vettel has spoken of his desire to drive for Ferrari in the future.
In addition, Alonso, who famously spent a tumultuous season alongside Hamilton at McLaren in 2007, is known to favour only having one world-class driver in a team and would be expected to be reluctant to accomodate Vettel.
When it was pointed out to Hamilton that Alonso's contract closed off a potential future career option for the next five years, Hamilton said: "I don't have a drama being alongside him, but I assume he wouldn't allow it to be the other way around."
Asked how he felt about that, the Englishman responded: "I don't really care. I'll beat him in another car."
The German said: "I never said anywhere that the fact that Fernando - or Felipe, or any other driver - drives for Ferrari [means] it is impossible to go there.
"As far as I know, F1 teams have two cars. Probably that kicks off some headlines. But I am very happy where I am so at this stage I don't care.
"In the end, we are all in the same boat. Ultimately we are looking for a package that makes us happy, whether that is results or the environment inside the team."
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.