John loved his sons very much and rather have them safe then the demon dead, but he has also been tracking this demon for years (over twenty years). It's unclear in the series what exactly John knew, but he knew a lot more then we think. He also knew that YED (The yellow-eyed Demon) had a grand plan that was revealed more in the fourth season, however at this point in the series we only knew that YED had plans for Sam and all the children like Sam (The demon told Sam and Dean at the end of the first season).
YED wants something else, something that he believed he could only get from John.
You said that you saw the fourth season, then think about Alastair for a moment and what he said to Dean in the episode "On The Head of a Pin." He told Dean that it was suppose to be his Dad, however, it turned out that Dean was the one they needed to take their key step in their evil plans.
The first two seasons have to do with the boys in the average episode, but the mythology arch of the show is more about Sam. The demons didn't care about Dean until the end of the second season. They were very focus on Sam and Dean slipped through the crack, until season three. The demons also took notice of John, which is why I believe that John decided to make the deal. First, he knew that the demons didn't care about Dean and what happened to him. Second, John knew the demon wouldn't be able to resisted making a deal. (A lot of demon deal happen in this series). John was very reckless at times and did things just for family purely on emotions like Dean. However, what John thought or what he knew has never been addressed. John wanted to protect both his sons and he knew that Dean was much stronger and could handle the things to come better than him.
Personally, I like the first two seasons the best!!! Just remember, Yellow-eyes has these plans and everyone has their part to play. Each Winchester has to play a role and John just walked into his and laid the foundation for Dean's. Sam's part maybe in your face this season, but it didn't come clear what it was until the end of the fourth season and the beginning of the fifth.