Felipe Massa has signed a two-year contract extension with Ferrari which will see the Brazilian remain at the team until the end of the 2012 season.

Massa has driven for Ferrari since 2006 and missed out on the championship by a single point to Lewis Hamilton two years later.

The 29-year-old suffered a near-fatal crash in Hungary last year but made his return to racing this season and sits seventh in the drivers' standings ahead of this weekend's Canadian Grand Prix.

"I am happy to be given the opportunity to drive for Ferrari for a further two seasons," Massa said in a statement released by Ferrari.

"Throughout my entire Formula One career, I have always raced with an engine made in Maranello and it is a matter of pride for me to be able to continue working with a team that I regard as a second family."

Massa, who signed for Ferrari in 2001 before being farmed out for two stints at Sauber, had been widely expected to leave the Scuderia at the end of the season, with Enstone's Renault F1 team's Robert Kubica in the frame to take his seat.

However Ferrari have now set out their stall for the next two years, with Massa's team-mate Fernando Alonso already under contract until 2012.

"Felipe has been part of Ferrari for almost a decade and together with us, he has grown as a driver and as a man, going through some very difficult times as well as giving us moments of great happiness," said Ferrari team boss Stefano Domenicali.

"We wanted to show proof of stability for the future, believing in the worth of a driver pairing that is without equal in terms of talent, speed and its ability to work together for the good of the team."

Massa has won 11 out of 69 grands prix for the Italian team, while also amassing 30 podium finishes.