Yes, it is illegal. You are an adult and he is a minor, and sex with children is against the law.
Unlawful intercourse with a minor, Penal Code 261.5, can be a felony if the age difference is enough; fortunately, because he is less than three years younger, you can only be charged with a misdemeanor.
If you got pregnant, the baby is evidence of the offense. DNA testing can prove he is the father. (Tissue from an aborted fetus can also be DNA tested.)
Fortunately, cases like this are rarely prosecuted, where the "victim" is so close to 18 and the "perpetrator" is just a little older. Both you and your boyfriend should keep a low profile; if contacted by the police, politely decline to answer any questions and tell them you want a lawyer.
Please understand that this is a general discussion of legal principles by a California lawyer and does not create an attorney/client relationship. It's impossible to give detailed, accurate advice based on a few sentences on a website (and you shouldn't provide too much specific information about your legal matter on a public forum like this, anyway). You should always seek advice from an attorney licensed in your jurisdiction who can give you an informed opinion after reviewing all of the relevant information.
My colleague's answer is correct, but my experience is that prosecutors will seldom prosecute a female when there is only a small age difference, as there is here, and where the sexual encounter occurs in the context of a relationship. In any case, you are young and perhaps not fully aware of all of the consequences your relationship may have.
You certainly should not discuss your sexual relationship with your boyfriend, and if you are ever asked about it by police, neither of you should answer any questions and should ask to see a lawyer immediately.
If you are already involved in a sexual relationship with your boyfriend, you should definitely educate yourself about effective birth control methods and methods for limiting your risk of STD. Also be aware that pregnancy may result in physical evidence. Since pregnancy can be difficult to hide, you may be asking for trouble. My experience has been that most sex cases involving circumstances such as yours tend to arise as the result of unhappy parents.
In any case, Mr. Marshall already gave you the best advice you could get--keep a low profile.
My colleagues are correct. The other thing to be careful about are his parents and jealous friends. If they do not approve they can turn you in.
The response given is not intended to create, nor does it create an ongoing duty to respond to questions. The response does not form an attorney-client relationship, nor is it intended to be anything other than the educated opinion of the author. It should not be relied upon as legal advice. The response given is based upon the limited facts provided by the person asking the question. To the extent additional or different facts exist, the response might possibly change. Attorney is licensed to practice law only in the State of California. Responses are based solely on California law unless stated otherwise.