Genies are given power in exchange for servitude. When Jafar wished for the powers like Genie, he got his wish. But it's exactly like the saying "be careful what you wish for, you might just get it". Jafar got locked away until a master comes to let him out. Which happens in the sequel.
And yes, Genie was freed using Aladdin ' sAladdin's third wish, which he had promised him earlier in the movie. An act of kindness that freed Genie from his servitude.