
911 P.2d 403 (1996)
80 Wash.App. 717
The STATE of Washington, Respondent,
v.
Larry D. GROOM, Appellant.
No. 14107-1-III.
Court of Appeals of Washington, Division 3. Panel One.
February 29, 1996.
*404 John Henry Browne, Browne & Ressler, Seattle, Karen P. O'Shea, Seattle, for Appellant.
Alex B. Hernandez, III, Deputy Prosecuting Attorney, Ephrata, for Respondent.
MUNSON, Judge.
This is the first reported appellate case presenting the issue of whether a police officer may be held criminally liable for entering and searching a residence without a search warrant pursuant to RCW 10.79.040. There are no previous reported cases of prosecution under this statute since it was enacted in 1921. Laws of 1921, ch. 71, § 1.
Larry Groom was charged with three misdemeanors: first degree criminal trespass, RCW 9A.52.070; official misconduct, RCW 9A.80.010; and unlawful search without a warrant, RCW 10.79.040. The district court granted Officer Groom's motion to dismiss all three charges pursuant to State v. Knapstad, 107 Wash.2d 346, 729 P.2d 48 (1986).
The State appealed; the superior court reversed the dismissal of the unlawful search charge and affirmed dismissal of the criminal trespass and official misconduct charges. Officer Groom seeks review of the portion of that superior court order remanding the unlawful search charge for trial. The State filed a cross notice for review of that portion of the order affirming dismissal of the other two counts.
In response to Officer Groom's motion to dismiss, the State submitted an affidavit alleging the following undisputed facts:
In February 1993, Officer Groom was the police chief of the city of Soap Lake. Shortly before midnight on the evening of February 1, Chief Groom was investigating allegations of sexual misconduct which had been made against Officer Joe Mandoli. He went to Officer Mandoli's residence where he found the officer's patrol car with keys hanging from the gear shift. The door to the residence was unlocked, the lights were on, and a gun was visible. He did not enter but went back to his office and telephoned the residence. Receiving no answer, he returned in the company of Officer Tom Jones. He entered the residence and, according to Officer Jones, proceeded to search the bedroom, including looking under the mattress and into the closet. He then removed police equipment and uniforms.
According to Officer Groom's motion to dismiss, his purpose in going to Officer Mandoli's residence was to investigate whether Officer Mandoli had committed a sexual crime. When he found the home unlocked, he became concerned for Officer Mandoli's safety because one of the complainants had threatened retaliation. He alleges he removed uniforms and equipment from the residence pursuant to his duty under a city ordinance to account for the personal property of the police department.

UNLAWFUL SEARCH
Officer Groom contends the superior court's reversal of the district court's dismissal of the unlawful search charge was error. A trial court's dismissal of charges pursuant to Knapstad is proper only if, based *405 on the facts asserted by the State, no reasonable trier of facts could have found the essential elements of the crime beyond a reasonable doubt. Knapstad, 107 Wash.2d at 356-57, 729 P.2d 48; State v. Wilhelm, 78 Wash. App. 188, 191, 896 P.2d 105 (1995).
Officer Groom is charged with unlawful search pursuant to RCW 10.79.040:
It shall be unlawful for any policeman or other peace officer to enter and search any private dwelling house or place of residence without the authority of a search warrant issued upon a complaint as by law provided.
A literal application of this statute would render criminally liable any officer who searched a residence without a warrant, regardless of whether any recognized exceptions to the warrant requirement of the Fourth Amendment justified the search.[1]
In the context of a civil suit for violation of a plaintiff's civil right, the courts recognize an officer's qualified immunity:
The concept of the immunity of government officers from personal liability springs from the same root considerations that generated the doctrine of sovereign immunity. While the latter doctrinethat the "King can do no wrong"did not protect all government officers from personal liability, the common law soon recognized the necessity of permitting officials to perform their official functions free from the threat of suits for personal liability. This official immunity apparently rested, in its genesis, on two mutually dependent rationales: (1) the injustice, particularly in the absence of bad faith, of subjecting to liability an officer who is required, by the legal obligations of his position, to exercise discretion; (2) the danger that the threat of such liability would deter his willingness to execute his office with the decisiveness and the judgment required by the public good.
Scheuer v. Rhodes, 416 U.S. 232, 239-40, 94 S.Ct. 1683, 1688, 40 L.Ed.2d 90 (1974) (footnotes omitted).
The essential policy underlying the common law immunity of police officers to civil suit is that "the public interest requires decisions and action to enforce laws for the protection of the public." Scheuer, 416 U.S. at 241, 94 S.Ct. at 1689. The same reasoning justifies finding law enforcement officers are given common law qualified immunity from criminal prosecution for actions taken in good faith in the performance of their official functions. We hold a police officer may be held criminally liable for the warrantless search of a dwelling only if the search is undertaken in bad faith.[2]
For purposes of a motion to dismiss under Knapstad, then, the issue is whether the State's factual allegations are sufficient to support a factual determination Officer Groom conducted the warrantless search in bad faith. Officer Groom's claim he entered the residence because he was alarmed for Officer Mandoli's safety is belied by Officer Jones's description of his actions in searching in closets and under a mattress. The State alleges Officer Groom went to Officer Mandoli's home to speak to him about an internal investigation or to terminate his employment. Officer Groom's actions would support an inference his purpose in searching the residence was to discover any evidence which would be useful to this investigation. The State's allegations were sufficient to create a triable issue of fact as to whether Officer Groom conducted the search in bad faith.

DISMISSAL OF OTHER CHARGES
The State contends the district court erred when it dismissed the criminal trespass and *406 official misconduct charges. Dismissal is proper only if the court concludes that no rational trier of fact could have found beyond a reasonable doubt the essential elements of the crime. Knapstad, 107 Wash.2d at 356-57, 729 P.2d 48.
The concept of qualified immunity of public officials is incorporated in the definition of official misconduct "if, with intent to... deprive another person of a lawful right or privilege ... [h]e intentionally commits an unauthorized act under color of law...." RCW 9A.80.010(1)(a). A person is guilty of criminal trespass in the first degree if he knowingly enters or remains unlawfully in a building. RCW 9A.52.070. When the defendant is a police officer, qualified immunity would require evidence of an intent to cause a deprivation of constitutional rights or other injury.
Evidence Officer Groom returned to his office and telephoned Officer Mandoli's residence before returning and entering supports the inference the subsequent entry was not justified by exigent circumstances or concern for Officer Mandoli's safety. The Soap Lake ordinances requiring accountability for city property do not authorize the police chief to enter a residence without a warrant. Officer Groom has never alleged the entry was authorized by warrant. A fact finder could infer Officer Groom knew there was no lawful basis for his entering the residence. Thus, the evidence is sufficient to support finding Officer Groom knowingly entered or remained in the building unlawfully, thereby committing criminal trespass. As with the unlawful search charge, the circumstances would permit a trier of fact to infer Officer Groom entered the residence for the purpose of obtaining evidence relating to allegations of Officer Mandoli's misconduct, a purpose violative of the officer's Fourth Amendment rights.
Officer Groom's version of the events in question asserts facts which, if believed by a jury, provide him with a defense. The existence of a meritorious defense is not relevant to the determination of a motion to dismiss under Knapstad.
"Prosecutors are vested with wide discretion in determining whether to charge suspects with criminal offenses. Exercise of this discretion involves consideration of factors such as the public interest as well as the strength of the case which could be proven." State v. Judge, 100 Wash.2d 706, 713, 675 P.2d 219 (1984) (citations omitted). The State has shown sufficient facts to support convictions on these offenses; the decision to charge was within the prosecutor's discretion. Whether a jury would agree is a matter to be determined.
Remanded for trial on all counts.
SWEENEY, C.J., and SCHULTHEIS, J., concur.
NOTES
[1]  "For example, when premises contain persons in imminent danger of death or harm; objects likely to burn, explode, or otherwise cause harm; or information that will disclose the location of a threatened victim or the existence of such a threat, police may search those premises without first obtaining a warrant." State v. Lynd, 54 Wash.App. 18, 20, 771 P.2d 770 (1989). Other exceptions include a search incident to arrest, Chimel v. California, 395 U.S. 752, 89 S.Ct. 2034, 23 L.Ed.2d 685 (1969), or consent, State v. Cotten, 75 Wash.App. 669, 879 P.2d 971 (1994), review denied, 126 Wash.2d 1004, 891 P.2d 38 (1995).
[2]  In the context of a civil action, qualified immunity is available unless the officer knew or reasonably should have known the action taken would violate the constitution or the officer acted with malicious intent to cause injury or deprivation of constitutional rights. Hocker v. Woody, 95 Wash.2d 822, 824-25, 631 P.2d 372 (1981).
